diff options
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | diskstats.c | 4 | ||||
-rw-r--r-- | filesystem.c | 12 | ||||
-rw-r--r-- | network.c | 4 | ||||
-rw-r--r-- | util.c | 16 | ||||
-rw-r--r-- | util.h | 1 |
6 files changed, 36 insertions, 13 deletions
diff --git a/README.md b/README.md index 208ffef..e6c580a 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,9 @@ arguments can be used to select which devices to report on. The format for both is a comma-separated list of device names (e.g., `--diskstats-include=sda,sdb`). If an include list is provided, only those devices explicitly listed are included. Otherwise, all devices -not mentioned on the exclude list are included. +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. ### `filesystem` @@ -178,7 +180,9 @@ filesystem passes all three tests, it is included in the metrics. For each category, if an include list is specified, only the explicitly listed values are accepted -- this overrides even the `/` prefix test for devices. If an include list is not set, all values not on the -exclusion list are accepted. +exclusion list are accepted. If the given value ends in `*`, it +matches any string that begins with the part before the `*`; +otherwise, the match must be exact. The data is derived from scanning `/proc/mounts` and calling `statvfs(2)` on all lines that pass the inclusion checks. @@ -254,7 +258,9 @@ the loopback interface (`lo`). The `--network-include=` and list of interface names to explicitly include and exclude, respectively. If an include list is set, only those interfaces are included. Otherwise, all interfaces *not* mentioned in the exclude -list are included. +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. ### `textfile` diff --git a/diskstats.c b/diskstats.c index bc2b1a4..0b305fd 100644 --- a/diskstats.c +++ b/diskstats.c @@ -124,10 +124,10 @@ static void diskstats_collect(scrape_req *req, void *ctx_ptr) { // filter if (ctx->include) { - if (!slist_contains(ctx->include, dev)) + if (!slist_matches(ctx->include, dev)) continue; } else if (ctx->exclude) { - if (slist_contains(ctx->exclude, dev)) + if (slist_matches(ctx->exclude, dev)) continue; } diff --git a/filesystem.c b/filesystem.c index ca4e7f6..edb5b42 100644 --- a/filesystem.c +++ b/filesystem.c @@ -117,26 +117,26 @@ static void filesystem_collect(scrape_req *req, void *ctx_ptr) { continue; if (ctx->include_device) { - if (!slist_contains(ctx->include_device, *dev)) + if (!slist_matches(ctx->include_device, *dev)) continue; } else { if (**dev != '/') continue; - if (ctx->exclude_device && slist_contains(ctx->exclude_device, *dev)) + if (ctx->exclude_device && slist_matches(ctx->exclude_device, *dev)) continue; } if (ctx->include_mount) { - if (!slist_contains(ctx->include_mount, *mount)) + if (!slist_matches(ctx->include_mount, *mount)) continue; } else if (ctx->exclude_mount) { - if (slist_contains(ctx->exclude_mount, *mount)) + if (slist_matches(ctx->exclude_mount, *mount)) continue; } if (ctx->include_type) { - if (!slist_contains(ctx->include_type, *fstype)) + if (!slist_matches(ctx->include_type, *fstype)) continue; } else if (ctx->exclude_type) { - if (slist_contains(ctx->exclude_type, *fstype)) + if (slist_matches(ctx->exclude_type, *fstype)) continue; } diff --git a/network.c b/network.c index ece1998..5eb2715 100644 --- a/network.c +++ b/network.c @@ -180,10 +180,10 @@ static void network_collect(scrape_req *req, void *ctx_ptr) { p++; if (ctx->include) { - if (!slist_contains(ctx->include, dev)) + if (!slist_matches(ctx->include, dev)) continue; } else if (ctx->exclude) { - if (slist_contains(ctx->exclude, dev)) + if (slist_matches(ctx->exclude, dev)) continue; } diff --git a/util.c b/util.c index 976de0b..1d85d5c 100644 --- a/util.c +++ b/util.c @@ -168,6 +168,22 @@ bool slist_contains(const struct slist *list, const char *key) { return false; } +bool slist_matches(const struct slist *list, const char *key) { + size_t key_len = strlen(key); + + for (; list; list = list->next) { + size_t match_len = strlen(list->data); + if (match_len > 0 && list->data[match_len-1] == '*') { + if (match_len-1 <= key_len && memcmp(list->data, key, match_len-1) == 0) + return true; + } else { + if (match_len == key_len && memcmp(list->data, key, key_len) == 0) + return true; + } + } + return false; +} + // miscellaneous utilities void *must_malloc(size_t size) { diff --git a/util.h b/util.h index 173b2a9..b87ad5f 100644 --- a/util.h +++ b/util.h @@ -47,6 +47,7 @@ struct slist *slist_split(const char *str, const char *delim); struct slist **slist_append(struct slist **prev, const char *str); struct slist *slist_prepend(struct slist *list, const char *str); bool slist_contains(const struct slist *list, const char *key); +bool slist_matches(const struct slist *list, const char *key); // miscellaneous utilities |