From: Florian Forster Date: Thu, 4 Jan 2024 06:37:49 +0000 (+0100) Subject: memory plugin: Add the "system.memory.limit" metric. X-Git-Tag: 6.0.0-rc0~10^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9f1a78d54910cb871a25cc1e617afa5be030b512;p=thirdparty%2Fcollectd.git memory plugin: Add the "system.memory.limit" metric. --- diff --git a/src/collectd.conf.in b/src/collectd.conf.in index c8f2444ce..8334c89e1 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1058,6 +1058,7 @@ # # ReportUsage true # ReportUtilization true +# ReportLimit false # # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 75447631e..bc6c2b87f 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -5282,6 +5282,11 @@ memory, e.g. the fraction of physical memory used. Defaults to B. This is useful for deploying I in a heterogeneous environment in which the sizes of physical memory vary. +=item B B|B + +Controls reporting of the total amount of physical memory available to the +system. Defaults to B. + =back =head2 Plugin C diff --git a/src/memory.c b/src/memory.c index a1b0b6070..0735c8c28 100644 --- a/src/memory.c +++ b/src/memory.c @@ -151,6 +151,7 @@ static int pagesize; static bool report_usage = true; static bool report_utilization = true; +static bool report_limit; static int memory_config(oconfig_item_t *ci) /* {{{ */ { @@ -162,6 +163,8 @@ static int memory_config(oconfig_item_t *ci) /* {{{ */ else if (strcasecmp("ReportUtilization", child->key) == 0 || strcasecmp("ValuesPercentage", child->key) == 0) cf_util_get_boolean(child, &report_utilization); + else if (strcasecmp("ReportLimit", child->key) == 0) + cf_util_get_boolean(child, &report_limit); else ERROR("memory plugin: Invalid configuration option: \"%s\".", child->key); } @@ -202,14 +205,34 @@ static int memory_dispatch(gauge_t values[COLLECTD_MEMORY_TYPE_MAX]) { } metric_family_metric_reset(&fam_usage); - if (!report_utilization) { - return ret; - } - if (total == 0) { return EINVAL; } + if (report_limit) { + metric_family_t fam_limit = { + .name = "system.memory.limit", + .help = "Total memory available in the system.", + .unit = "By", + .type = METRIC_TYPE_COUNTER, // [sic] should be UpDownCounter + }; + metric_t m = { + .value = (value_t){.derive = (derive_t)total}, + }; + metric_family_metric_append(&fam_limit, m); + + int status = plugin_dispatch_metric_family(&fam_limit); + if (status != 0) { + ERROR("memory plugin: plugin_dispatch_metric_family failed: %s", + STRERROR(status)); + } + ret = ret ? ret : status; + } + + if (!report_utilization) { + return ret; + } + metric_family_t fam_util = { .name = "system.memory.utilization", .help = "Reports memory in use by state",