about summary refs log tree commit diff
path: root/filefd.c
diff options
context:
space:
mode:
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);
+}