diff options
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | diskstats.c | 9 |
2 files changed, 13 insertions, 1 deletions
diff --git a/README.md b/README.md index e6c580a..abb2cc0 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ The metrics correspond to the columns of `/proc/diskstats`: See the kernel's [Documentation/iostats.txt](https://www.kernel.org/doc/Documentation/iostats.txt) -for more details. The collector assumes the read/write totals are +file for more details. The collector assumes the read/write totals are reported using a sector size of 512 bytes. All metrics have one label, `device`, containing the device name from @@ -149,6 +149,9 @@ not mentioned on the exclude list are included. If the given value ends in `*`, it matches any string that begins with the part before the `*`; otherwise, the match must be exact. +By default, if the device is entirely unused (all metrics are 0), it's +omitted. Use `--diskstats-keep-unused` to include even those devices. + ### `filesystem` Metrics: 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 |