diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | filefd.c | 33 | ||||
-rw-r--r-- | main.c | 1 |
3 files changed, 35 insertions, 0 deletions
diff --git a/Makefile b/Makefile index e307148..a7b3034 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ COLLECTORS = COLLECTORS += cpu COLLECTORS += diskstats COLLECTORS += filesystem +COLLECTORS += filefd COLLECTORS += hwmon COLLECTORS += meminfo COLLECTORS += netdev diff --git a/filefd.c b/filefd.c new file mode 100644 index 0000000..b565d5f --- /dev/null +++ b/filefd.c @@ -0,0 +1,33 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "scrape.h" +#include "util.h" + +static void filefd_collect(scrape_req *req, void *ctx); + +const struct collector filefd_collector = { + .name = "filefd", + .collect = filefd_collect, +}; + +static void filefd_collect(scrape_req *req, void *ctx) { + (void) ctx; + + FILE *f; + + // scan /proc/sys/fs/file-nr for metrics + + f = fopen(PATH("/proc/sys/fs/file-nr"), "r"); + if (!f) + return; + + double alloc, ignored, max; + if (fscanf(f, "%lf %lf %lf", &alloc, &ignored, &max) == 3) { + scrape_write(req, "node_filefd_allocated", 0, alloc); + scrape_write(req, "node_filefd_maximum", 0, max); + } + + fclose(f); +} diff --git a/main.c b/main.c index f8515af..c66ad03 100644 --- a/main.c +++ b/main.c @@ -32,6 +32,7 @@ #define XCOLLECTORS \ X(cpu) \ X(diskstats) \ + X(filefd) \ X(filesystem) \ X(hwmon) \ X(loadavg) \ |