From: Florian Forster Date: Wed, 7 Feb 2024 16:19:18 +0000 (+0100) Subject: memory plugin: Report the `system.linux.memory.available` metric. X-Git-Tag: collectd-6.0.0.rc3~8^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F4275%2Fhead;p=thirdparty%2Fcollectd.git memory plugin: Report the `system.linux.memory.available` metric. --- diff --git a/src/memory.c b/src/memory.c index 1135da9f5..46c232a51 100644 --- a/src/memory.c +++ b/src/memory.c @@ -257,6 +257,26 @@ static int memory_dispatch(gauge_t values[STATE_MAX]) { return ret; } +#if KERNEL_LINUX +static int system_linux_memory_available(gauge_t available) { + metric_family_t fam = { + .name = "system.linux.memory.available", + .help = "An estimate of how much memory is available for starting new " + "applications, without causing swapping.", + .unit = "By", + .type = METRIC_TYPE_GAUGE, + }; + metric_family_metric_append(&fam, (metric_t){ + .value.gauge = available, + }); + + int err = plugin_dispatch_metric_family(&fam); + metric_family_metric_reset(&fam); + + return err; +} +#endif + static int memory_init(void) { #if HAVE_HOST_STATISTICS port_host = mach_host_self(); @@ -464,6 +484,8 @@ static int memory_read_internal(gauge_t values[STATE_MAX]) { } else if (strcmp(fields[0], "Shmem:") == 0) { values[STATE_SHARED] = v; mem_not_used += v; + } else if (strcmp(fields[0], "MemAvailable:") == 0) { + system_linux_memory_available(v); } }