diff options
author | Vladimir Kobal <vlad@prokk.net> | 2019-04-03 17:38:03 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-03 17:38:03 +0300 |
commit | b48ea20e0b1c0005d267db9c072edbc67982cf1a (patch) | |
tree | 06851abbb34847f919ec9cdb0f2afc5668af8d7e /collectors/proc.plugin | |
parent | 537a39ee844ca57fcf505223a15be2b301239cb9 (diff) |
Add preferred disk id pattern (#5779)
* Add simple pattern for preferred disk ids
* Update the documentation
* Fix typo
* Preserve the customary naming
* Fix typo
Diffstat (limited to 'collectors/proc.plugin')
-rw-r--r-- | collectors/proc.plugin/README.md | 51 | ||||
-rw-r--r-- | collectors/proc.plugin/proc_diskstats.c | 28 |
2 files changed, 53 insertions, 26 deletions
diff --git a/collectors/proc.plugin/README.md b/collectors/proc.plugin/README.md index c484b11d65..37dc19f865 100644 --- a/collectors/proc.plugin/README.md +++ b/collectors/proc.plugin/README.md @@ -71,7 +71,7 @@ Hopefully, the Linux kernel provides many metrics that can provide deep insights ### disk names -netdata will automatically set the name of disks on the dashboard, from the mount point they are mounted, of course only when they are mounted. Changes in mount points are not currently detected (you will have to restart netdata to change the name of the disk). +netdata will automatically set the name of disks on the dashboard, from the mount point they are mounted, of course only when they are mounted. Changes in mount points are not currently detected (you will have to restart netdata to change the name of the disk). To use disk IDs provided by `/dev/disk/by-id`, the `name disks by id` option should be enabled. The `preferred disk ids` simple pattern allows choosing disk IDs to be used in the first place. ### performance metrics @@ -99,28 +99,33 @@ Then edit `netdata.conf` and find the following section. This is the basic plugi ``` [plugin:proc:/proc/diskstats] - # enable new disks detected at runtime = yes - # performance metrics for physical disks = auto - # performance metrics for virtual disks = no - # performance metrics for partitions = no - # performance metrics for mounted filesystems = no - # performance metrics for mounted virtual disks = auto - # space metrics for mounted filesystems = auto - # bandwidth for all disks = auto - # operations for all disks = auto - # merged operations for all disks = auto - # i/o time for all disks = auto - # queued operations for all disks = auto - # utilization percentage for all disks = auto - # backlog for all disks = auto - # space usage for all disks = auto - # inodes usage for all disks = auto - # filename to monitor = /proc/diskstats - # path to get block device infos = /sys/dev/block/%lu:%lu/%s - # path to get h/w sector size = /sys/block/%s/queue/hw_sector_size - # path to get h/w sector size for partitions = /sys/dev/block/%lu:%lu/subsystem/%s/../queue -/hw_sector_size - + # enable new disks detected at runtime = yes + # performance metrics for physical disks = auto + # performance metrics for virtual disks = auto + # performance metrics for partitions = no + # bandwidth for all disks = auto + # operations for all disks = auto + # merged operations for all disks = auto + # i/o time for all disks = auto + # queued operations for all disks = auto + # utilization percentage for all disks = auto + # backlog for all disks = auto + # bcache for all disks = auto + # bcache priority stats update every = 0 + # remove charts of removed disks = yes + # path to get block device = /sys/block/%s + # path to get block device bcache = /sys/block/%s/bcache + # path to get virtual block device = /sys/devices/virtual/block/%s + # path to get block device infos = /sys/dev/block/%lu:%lu/%s + # path to device mapper = /dev/mapper + # path to /dev/disk/by-label = /dev/disk/by-label + # path to /dev/disk/by-id = /dev/disk/by-id + # path to /dev/vx/dsk = /dev/vx/dsk + # name disks by id = no + # preferred disk ids = * + # exclude disks = loop* ram* + # filename to monitor = /proc/diskstats + # performance metrics for disks with major 8 = yes ``` For each virtual disk, physical disk and partition you will have a section like this: diff --git a/collectors/proc.plugin/proc_diskstats.c b/collectors/proc.plugin/proc_diskstats.c index 7e8bee1e72..cd467948c2 100644 --- a/collectors/proc.plugin/proc_diskstats.c +++ b/collectors/proc.plugin/proc_diskstats.c @@ -11,6 +11,7 @@ #define DISK_TYPE_PARTITION 2 #define DISK_TYPE_VIRTUAL 3 +#define DEFAULT_PREFERRED_IDS "*" #define DEFAULT_EXCLUDED_DISKS "loop* ram*" static struct disk { @@ -164,6 +165,7 @@ static int global_enable_new_disks_detected_at_runtime = CONFIG_BOOLEAN_YES, globals_initialized = 0, global_cleanup_removed_disks = 1; +static SIMPLE_PATTERN *preferred_ids = NULL; static SIMPLE_PATTERN *excluded_disks = NULL; static unsigned long long int bcache_read_number_with_units(const char *filename) { @@ -316,7 +318,9 @@ static inline int is_major_enabled(int major) { static inline int get_disk_name_from_path(const char *path, char *result, size_t result_size, unsigned long major, unsigned long minor, char *disk, char *prefix, int depth) { //info("DEVICE-MAPPER ('%s', %lu:%lu): examining directory '%s' (allowed depth %d).", disk, major, minor, path, depth); - int found = 0; + int found = 0, preferred = 0; + + char *first_result = mallocz(result_size); DIR *dir = opendir(path); if (!dir) { @@ -394,8 +398,16 @@ static inline int get_disk_name_from_path(const char *path, char *result, size_t //info("DEVICE-MAPPER ('%s', %lu:%lu): filename '%s' matches.", disk, major, minor, filename); snprintfz(result, result_size - 1, "%s%s%s", (prefix)?prefix:"", (prefix)?"_":"", de->d_name); - found = 1; - break; + + if(!found) { + strncpyz(first_result, result, result_size); + found = 1; + } + + if(simple_pattern_matches(preferred_ids, result)) { + preferred = 1; + break; + } } } closedir(dir); @@ -405,6 +417,10 @@ failed: if(!found) result[0] = '\0'; + else if(!preferred) + strncpyz(result, first_result, result_size); + + freez(first_result); return found; } @@ -835,6 +851,12 @@ int do_proc_diskstats(int update_every, usec_t dt) { name_disks_by_id = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_DISKSTATS, "name disks by id", name_disks_by_id); + preferred_ids = simple_pattern_create( + config_get(CONFIG_SECTION_PLUGIN_PROC_DISKSTATS, "preferred disk ids", DEFAULT_PREFERRED_IDS) + , NULL + , SIMPLE_PATTERN_EXACT + ); + excluded_disks = simple_pattern_create( config_get(CONFIG_SECTION_PLUGIN_PROC_DISKSTATS, "exclude disks", DEFAULT_EXCLUDED_DISKS) , NULL |