Skip to content

Commit

Permalink
memory.c: add "Dirty" and "Writeback" with conf option
Browse files Browse the repository at this point in the history
Signed-off-by: zzzyhtheonly <zyhtheonly@yeah.net>
  • Loading branch information
zzzyhtheonly committed Feb 29, 2024
1 parent 3a3ef49 commit 7f3ee0c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
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
# ReportDirty 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<ReportDirty> 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
20 changes: 17 additions & 3 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("ReportDirty", 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,7 +427,12 @@ 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);
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
Expand Down

0 comments on commit 7f3ee0c

Please sign in to comment.