]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
memory plugin: Add the "system.memory.limit" metric.
authorFlorian Forster <octo@collectd.org>
Thu, 4 Jan 2024 06:37:49 +0000 (07:37 +0100)
committerFlorian Forster <octo@collectd.org>
Mon, 15 Jan 2024 14:21:58 +0000 (15:21 +0100)
src/collectd.conf.in
src/collectd.conf.pod
src/memory.c

index c8f2444ce1832a1e804d33f0b9d2850c782650ba..8334c89e145a4e52b1cd194a091bbba8cf256516 100644 (file)
 #<Plugin memory>
 #      ReportUsage true
 #      ReportUtilization true
+#      ReportLimit false
 #</Plugin>
 
 #<Plugin mmc>
index 75447631e9515b8449b0f6e8afa390d00815fc6a..bc6c2b87f5d4eef5df703947623c54a70e12dc02 100644 (file)
@@ -5282,6 +5282,11 @@ memory, e.g. the fraction of physical memory used. Defaults to B<true>.
 This is useful for deploying I<collectd> in a heterogeneous environment in
 which the sizes of physical memory vary.
 
+=item B<ReportLimit> B<false>|B<true>
+
+Controls reporting of the total amount of physical memory available to the
+system. Defaults to B<true>.
+
 =back
 
 =head2 Plugin C<modbus>
index a1b0b6070549a254a26acbf9a535833d7578041b..0735c8c283479c9dacef7bd02e09469c7449b800 100644 (file)
@@ -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",