about summary refs log tree commit diff
path: root/filesystem.c
diff options
context:
space:
mode:
authorHeikki Kallasjoki <fis@zem.fi>2018-11-30 17:25:14 +0000
committerHeikki Kallasjoki <fis@zem.fi>2018-11-30 17:25:17 +0000
commitefee4edcad70b4d53c1f258e4f5f955a223006e9 (patch)
tree2ad24ec1d4dedd43505649758b67e971fb06679f /filesystem.c
parent7aa7f859f29d87d5b2628ad7f1dca27f36ceae13 (diff)
downloadnano-exporter-efee4edcad70b4d53c1f258e4f5f955a223006e9.tar.gz
nano-exporter-efee4edcad70b4d53c1f258e4f5f955a223006e9.tar.xz
nano-exporter-efee4edcad70b4d53c1f258e4f5f955a223006e9.zip
Support include/exclude lists in the filesystem collector.
Diffstat (limited to 'filesystem.c')
-rw-r--r--filesystem.c74
1 files changed, 69 insertions, 5 deletions
diff --git a/filesystem.c b/filesystem.c
index d31518e..6ed4407 100644
--- a/filesystem.c
+++ b/filesystem.c
@@ -9,15 +9,59 @@
 // size of input buffer for paths and lines
 #define BUF_SIZE 256
 
+static void *filesystem_init(int argc, char *argv[]);
 static void filesystem_collect(scrape_req *req, void *ctx);
 
 const struct collector filesystem_collector = {
   .name = "filesystem",
   .collect = filesystem_collect,
+  .init = filesystem_init,
+  .has_args = true,
 };
 
-static void filesystem_collect(scrape_req *req, void *ctx) {
-  (void) ctx;
+struct filesystem_context {
+  struct slist *include_device;
+  struct slist *exclude_device;
+  struct slist *include_mount;
+  struct slist *exclude_mount;
+  struct slist *include_type;
+  struct slist *exclude_type;
+};
+
+static void *filesystem_init(int argc, char *argv[]) {
+  struct filesystem_context *ctx = must_malloc(sizeof *ctx);
+
+  ctx->include_device = 0;
+  ctx->exclude_device = 0;
+  ctx->include_mount = 0;
+  ctx->exclude_mount = 0;
+  ctx->include_type = 0;
+  ctx->exclude_type = 0;
+
+  for (int arg = 0; arg < argc; arg++) {
+    if (strncmp(argv[arg], "include-device=", 15) == 0) {
+      ctx->include_device = slist_split(&argv[arg][15], ",");
+    } else if (strncmp(argv[arg], "exclude-device=", 15) == 0) {
+      ctx->exclude_device = slist_split(&argv[arg][15], ",");
+    } else if (strncmp(argv[arg], "include-mount=", 14) == 0) {
+      ctx->include_mount = slist_split(&argv[arg][14], ",");
+    } else if (strncmp(argv[arg], "exclude-mount=", 14) == 0) {
+      ctx->exclude_mount = slist_split(&argv[arg][14], ",");
+    } else if (strncmp(argv[arg], "include-type=", 13) == 0) {
+      ctx->include_type = slist_split(&argv[arg][13], ",");
+    } else if (strncmp(argv[arg], "exclude-type=", 13) == 0) {
+      ctx->exclude_type = slist_split(&argv[arg][13], ",");
+    } else {
+      fprintf(stderr, "unknown argument for filesystem collector: %s", argv[arg]);
+      return 0;
+    }
+  }
+
+  return ctx;
+}
+
+static void filesystem_collect(scrape_req *req, void *ctx_ptr) {
+  struct filesystem_context *ctx = ctx_ptr;
 
   // buffers
 
@@ -56,9 +100,29 @@ static void filesystem_collect(scrape_req *req, void *ctx) {
     if (!*fstype)
       continue;
 
-    if (**dev != '/')
-      continue;
-    // TODO: device, mountpoint, filesystem exclude lists
+    if (ctx->include_device) {
+      if (!slist_contains(ctx->include_device, *dev))
+        continue;
+    } else {
+      if (**dev != '/')
+        continue;
+      if (ctx->exclude_device && slist_contains(ctx->exclude_device, *dev))
+        continue;
+    }
+    if (ctx->include_mount) {
+      if (!slist_contains(ctx->include_mount, *mount))
+        continue;
+    } else if (ctx->exclude_mount) {
+      if (slist_contains(ctx->exclude_mount, *mount))
+        continue;
+    }
+    if (ctx->include_type) {
+      if (!slist_contains(ctx->include_type, *fstype))
+        continue;
+    } else if (ctx->exclude_type) {
+      if (slist_contains(ctx->exclude_type, *fstype))
+        continue;
+    }
 
     // report metrics from statfs