From 1914c852c4687ed2b58bad04833dc48d1f5c076a Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 7 Feb 2024 17:19:18 +0100 Subject: [PATCH] memory plugin: Report the `system.linux.memory.available` metric. --- src/memory.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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); } } -- 2.47.2