Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory.c: add "Dirty" and "Writeback" with conf option #4292

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/collectd.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@
#<Plugin memory>
# ValuesAbsolute true
# ValuesPercentage false
# ReportMem4IOwrite false
#</Plugin>

#<Plugin mmc>
Expand Down
6 changes: 6 additions & 0 deletions src/collectd.conf.pod
Original file line number Diff line number Diff line change
Expand Up @@ -5169,6 +5169,12 @@ percent of physical memory used. Defaults to B<false>.
This is useful for deploying I<collectd> in a heterogeneous environment in
which the sizes of physical memory vary.

=item B<ReportMem4IOwrite> B<false>|B<true>

Enables or disables reporting of "Dirty" and "Writeback" metrics. Which are
always absolute numbers in bytes and do not count in B<ValuesPercentage>.
Defaults to B<false>.

=back

=head2 Plugin C<modbus>
Expand Down
22 changes: 18 additions & 4 deletions src/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ static int pagesize;

static bool values_absolute = true;
static bool values_percentage;
static bool report_dirty_friends;

static int memory_config(oconfig_item_t *ci) /* {{{ */
{
Expand All @@ -117,6 +118,8 @@ static int memory_config(oconfig_item_t *ci) /* {{{ */
cf_util_get_boolean(child, &values_absolute);
else if (strcasecmp("ValuesPercentage", child->key) == 0)
cf_util_get_boolean(child, &values_percentage);
else if (strcasecmp("ReportMem4IOwrite", child->key) == 0)
cf_util_get_boolean(child, &report_dirty_friends);
else
ERROR("memory plugin: Invalid configuration option: "
"\"%s\".",
Expand Down Expand Up @@ -186,15 +189,15 @@ static int memory_init(void) {
} while (0)

#if KERNEL_LINUX
static void memory_submit_available(gauge_t value) {
static void memory_submit_single(gauge_t value, const char *type_instance) {
value_list_t vl = VALUE_LIST_INIT;

vl.values = &(value_t){.gauge = value};
vl.values_len = 1;

sstrncpy(vl.plugin, "memory", sizeof(vl.plugin));
sstrncpy(vl.type, "memory", sizeof(vl.type));
sstrncpy(vl.type_instance, "available", sizeof(vl.type_instance));
sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));

plugin_dispatch_values(&vl);
}
Expand Down Expand Up @@ -350,6 +353,8 @@ static int memory_read_internal(value_list_t *vl) {
gauge_t mem_cached = 0;
gauge_t mem_free = 0;
gauge_t mem_available = 0;
gauge_t mem_dirty = 0;
gauge_t mem_writeback = 0;
gauge_t mem_slab_total = 0;
gauge_t mem_slab_reclaimable = 0;
gauge_t mem_slab_unreclaimable = 0;
Expand All @@ -370,6 +375,10 @@ static int memory_read_internal(value_list_t *vl) {
val = &mem_buffered;
else if (strncasecmp(buffer, "Cached:", 7) == 0)
val = &mem_cached;
else if (strncasecmp(buffer, "Dirty:", 6) == 0)
val = &mem_dirty;
else if (strncasecmp(buffer, "Writeback:", 10) == 0)
val = &mem_writeback;
else if (strncasecmp(buffer, "Slab:", 5) == 0)
val = &mem_slab_total;
else if (strncasecmp(buffer, "SReclaimable:", 13) == 0) {
Expand Down Expand Up @@ -418,8 +427,13 @@ static int memory_read_internal(value_list_t *vl) {
mem_cached, "free", mem_free, "slab", mem_slab_total);

if (mem_available_info)
memory_submit_available(mem_available);
/* #endif KERNEL_LINUX */
memory_submit_single(mem_available, "available");

if (report_dirty_friends) {
memory_submit_single(mem_dirty, "dirty");
memory_submit_single(mem_writeback, "writeback");
}
/* #endif KERNEL_LINUX */

#elif HAVE_LIBKSTAT
/* Most of the additions here were taken as-is from the k9toolkit from
Expand Down