From: Florian Forster Date: Wed, 10 Jan 2024 21:00:03 +0000 (+0100) Subject: swap plugin: Add the `ReportUsage` and `ReportUtilization` config options. X-Git-Tag: collectd-6.0.0.rc1~2^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c1449992bb7b3b79120dc2a5714b0557c3666da;p=thirdparty%2Fcollectd.git swap plugin: Add the `ReportUsage` and `ReportUtilization` config options. --- diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 18dd82ef6..a269306ab 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1748,10 +1748,10 @@ # # ReportByDevice false -# ReportBytes true -# ValuesAbsolute true -# ValuesPercentage false +# ReportUsage true +# ReportUtilization false # ReportIO true +# ReportBytes true # # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index b8b9457a9..d37892850 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -9334,17 +9334,18 @@ This option is only available if the I can read C =item B B|B When enabled, the I is reported in bytes. When disabled, the default, -I is reported in pages. This option is available under Linux only. +I is reported in pages. This option is available under Linux and +NetBSD only. -=item B B|B +=item B B|B Enables or disables reporting of absolute swap metrics, i.e. number of I available and used. Defaults to B. -=item B B|B +=item B B|B -Enables or disables reporting of relative swap metrics, i.e. I -available and free. Defaults to B. +Enables or disables reporting of relative swap metrics, i.e. the ratio of used +and free swap space. Defaults to B. This is useful for deploying I in a heterogeneous environment, where swap sizes differ and you want to specify generic thresholds or similar. diff --git a/src/swap.c b/src/swap.c index 1ac069204..e79f4fbc0 100644 --- a/src/swap.c +++ b/src/swap.c @@ -114,8 +114,8 @@ static int pagesize; #error "No applicable input method." #endif /* HAVE_LIBSTATGRAB */ -static bool values_absolute = true; -static bool values_percentage; +static bool report_usage = true; +static bool report_utilization; static bool report_io = true; static char const *const label_device = "system.device"; @@ -152,10 +152,13 @@ static int swap_config(oconfig_item_t *ci) /* {{{ */ "is not supported on this platform. " "The option is going to be ignored."); #endif /* SWAP_HAVE_REPORT_BY_DEVICE */ - else if (strcasecmp("ValuesAbsolute", child->key) == 0) - cf_util_get_boolean(child, &values_absolute); - else if (strcasecmp("ValuesPercentage", child->key) == 0) - cf_util_get_boolean(child, &values_percentage); + /* ValuesAbsolute and ValuesPercentage are for collectd 5 compatibility. */ + else if (strcasecmp("ReportUsage", child->key) == 0 || + strcasecmp("ValuesAbsolute", child->key) == 0) + cf_util_get_boolean(child, &report_usage); + else if (strcasecmp("ReportUtilization", child->key) == 0 || + strcasecmp("ValuesPercentage", child->key) == 0) + cf_util_get_boolean(child, &report_utilization); else if (strcasecmp("ReportIO", child->key) == 0) cf_util_get_boolean(child, &report_io); else @@ -222,7 +225,7 @@ static void swap_submit_usage3(metric_family_t *fams, char const *device, bool have_other = (other_name != NULL) && !isnan(other); - if (values_absolute) { + if (report_usage) { if (have_other) { metric_family_append(fam_usage, label_state, other_name, (value_t){.gauge = other}, &m); @@ -234,7 +237,7 @@ static void swap_submit_usage3(metric_family_t *fams, char const *device, (value_t){.gauge = free}, &m); } - if (values_percentage) { + if (report_utilization) { gauge_t total = used + free; if (have_other) { total += other;