diff options
author | Leah Neukirchen <leah@vuxu.org> | 2024-06-09 19:57:12 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2024-06-09 19:57:12 +0200 |
commit | ae3717a44deb305d5dca9151b2f7cb02a73cd6c1 (patch) | |
tree | 7daba18425876fe30600ab8ee441cbf48c2f43ad /pressure.c | |
parent | 9d5a71c7bab5e7273af938f974d97ef0098502fb (diff) | |
download | nano-exporter-ae3717a44deb305d5dca9151b2f7cb02a73cd6c1.tar.gz nano-exporter-ae3717a44deb305d5dca9151b2f7cb02a73cd6c1.tar.xz nano-exporter-ae3717a44deb305d5dca9151b2f7cb02a73cd6c1.zip |
add pressure (psi) collector
Diffstat (limited to 'pressure.c')
-rw-r--r-- | pressure.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/pressure.c b/pressure.c new file mode 100644 index 0000000..2c8033c --- /dev/null +++ b/pressure.c @@ -0,0 +1,47 @@ +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +#include "scrape.h" +#include "util.h" + +// size of input buffer for paths and lines +#define BUF_SIZE 256 + +static void pressure_collect(scrape_req *req, void *ctx); + +const struct collector pressure_collector = { + .name = "pressure", + .collect = pressure_collect, +}; + +static void pressure_collect(scrape_req *req, void *ctx) { + (void) ctx; + + FILE *f; + long long ms; + + if ((f = fopen("/proc/pressure/cpu", "r"))) { + if (fscanf(f, "some %*[^t]total=%lld\n", &ms) == 1) + scrape_write(req, "node_cpu_waiting_seconds_total", 0, ms / 1e6); + fclose(f); + } + + if ((f = fopen("/proc/pressure/memory", "r"))) { + if (fscanf(f, "some %*[^t]total=%lld\n", &ms) == 1) + scrape_write(req, "memory_waiting_seconds_total", 0, ms / 1e6); + if (fscanf(f, "full %*[^t]total=%lld\n", &ms) == 1) + scrape_write(req, "memory_stalled_seconds_total", 0, ms / 1e6); + fclose(f); + } + + if ((f = fopen("/proc/pressure/io", "r"))) { + if (fscanf(f, "some %*[^t]total=%lld\n", &ms) == 1) + scrape_write(req, "io_waiting_seconds_total", 0, ms / 1e6); + if (fscanf(f, "full %*[^t]total=%lld\n", &ms) == 1) + scrape_write(req, "io_stalled_seconds_total", 0, ms / 1e6); + fclose(f); + } +} |