diff options
author | Leah Neukirchen <leah@vuxu.org> | 2024-05-23 20:37:07 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2024-05-23 20:37:57 +0200 |
commit | 9e05852ac41fd8a97150197d6eddd04608b561b5 (patch) | |
tree | a78f9b0b200517f7a91fe30285dcb3b31b80ef3e /loadavg.c | |
parent | 55d111c0cba340a1e1df588f794be967a07aea68 (diff) | |
download | nano-exporter-9e05852ac41fd8a97150197d6eddd04608b561b5.tar.gz nano-exporter-9e05852ac41fd8a97150197d6eddd04608b561b5.tar.xz nano-exporter-9e05852ac41fd8a97150197d6eddd04608b561b5.zip |
add loadavg collector
Diffstat (limited to 'loadavg.c')
-rw-r--r-- | loadavg.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/loadavg.c b/loadavg.c new file mode 100644 index 0000000..9fa9146 --- /dev/null +++ b/loadavg.c @@ -0,0 +1,35 @@ +#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 loadavg_collect(scrape_req *req, void *ctx); + +const struct collector loadavg_collector = { + .name = "loadavg", + .collect = loadavg_collect, +}; + +static void loadavg_collect(scrape_req *req, void *ctx) { + (void) ctx; + + double loadavg[3]; + if (getloadavg(loadavg, 3) == 3) { + scrape_write(req, "node_load1", 0, loadavg[0]); + scrape_write(req, "node_load5", 0, loadavg[1]); + scrape_write(req, "node_load15", 0, loadavg[2]); + } + + struct timespec ts; + if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) < 0) + return; + double d = ts.tv_sec + ts.tv_nsec / 1e9; + scrape_write(req, "process_cpu_seconds_total", 0, d); +} |