diff options
author | Heikki Kallasjoki <fis@zem.fi> | 2018-11-30 22:28:10 +0000 |
---|---|---|
committer | Heikki Kallasjoki <fis@zem.fi> | 2018-11-30 22:28:10 +0000 |
commit | 11766041777085ef2746aedda66bf9483a7f1892 (patch) | |
tree | 848a4b20ef2bd0a30226dff4d34dce82a63a0ef2 /diskstats.c | |
parent | 202a4f83a9449a0d36b9475435233e5773d490aa (diff) | |
download | nano-exporter-11766041777085ef2746aedda66bf9483a7f1892.tar.gz nano-exporter-11766041777085ef2746aedda66bf9483a7f1892.tar.xz nano-exporter-11766041777085ef2746aedda66bf9483a7f1892.zip |
Filter out unused devices from diskstats.
Diffstat (limited to 'diskstats.c')
-rw-r--r-- | diskstats.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/diskstats.c b/diskstats.c index 0b305fd..873d939 100644 --- a/diskstats.c +++ b/diskstats.c @@ -42,6 +42,7 @@ const struct collector diskstats_collector = { struct diskstats_context { struct slist *include; struct slist *exclude; + bool filter_unused; }; static void *diskstats_init(int argc, char *argv[]) { @@ -49,12 +50,15 @@ static void *diskstats_init(int argc, char *argv[]) { ctx->include = 0; ctx->exclude = 0; + ctx->filter_unused = true; for (int arg = 0; arg < argc; arg++) { if (strncmp(argv[arg], "include=", 8) == 0) { ctx->include = slist_split(&argv[arg][8], ","); } else if (strncmp(argv[arg], "exclude=", 8) == 0) { ctx->exclude = slist_split(&argv[arg][8], ","); + } else if (strcmp(argv[arg], "keep-unused") == 0) { + ctx->filter_unused = false; } else { fprintf(stderr, "unknown argument for diskstats collector: %s", argv[arg]); return 0; @@ -130,6 +134,11 @@ static void diskstats_collect(scrape_req *req, void *ctx_ptr) { if (slist_matches(ctx->exclude, dev)) continue; } + if (ctx->filter_unused) { + char *tail = dev + strlen(dev) + 1; + if (tail < buf + sizeof buf && strspn(tail, " 0\n") == strlen(tail)) + continue; // only spaces, zeros and newlines: unused device + } // emit metrics while known columns last |