about summary refs log tree commit diff
path: root/filefd.c
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2024-05-23 20:39:18 +0200
committerLeah Neukirchen <leah@vuxu.org>2024-05-23 20:39:18 +0200
commitf8acb1e0546d9aca6d018a1ab70e2d3921be7c55 (patch)
treeff1d3639cb865ea60b1705575e1a8b127411b9ad /filefd.c
parent9e05852ac41fd8a97150197d6eddd04608b561b5 (diff)
downloadnano-exporter-f8acb1e0546d9aca6d018a1ab70e2d3921be7c55.tar.gz
nano-exporter-f8acb1e0546d9aca6d018a1ab70e2d3921be7c55.tar.xz
nano-exporter-f8acb1e0546d9aca6d018a1ab70e2d3921be7c55.zip
add filefd collector
Diffstat (limited to 'filefd.c')
-rw-r--r--filefd.c33
1 files changed, 33 insertions, 0 deletions
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);
+}