@cryptotaxi247 / netdata-1 / commits / b48ea20e0

Add preferred disk id pattern (#5779)

* Add simple pattern for preferred disk ids * Update the documentation * Fix typo * Preserve the customary naming * Fix typo

Vladimir Kobal committed Apr 3, 2019 at 17:38 UTC b48ea20e0b1c0005d267db9c072edbc67982cf1a
2 files changed +53 -26
collectors/proc.plugin/README.md
+28 -23
@@ -71,7 +71,7 @@ Hopefully, the Linux kernel provides many metrics that can provide deep insights
71
72 ### disk names
73
74 -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).
74 +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.
75
76 ### performance metrics
77
@@ -99,28 +99,33 @@ Then edit `netdata.conf` and find the following section. This is the basic plugi
99
100 ```
101 [plugin:proc:/proc/diskstats]
102 - # enable new disks detected at runtime = yes
103 - # performance metrics for physical disks = auto
104 - # performance metrics for virtual disks = no
105 - # performance metrics for partitions = no
106 - # performance metrics for mounted filesystems = no
107 - # performance metrics for mounted virtual disks = auto
108 - # space metrics for mounted filesystems = auto
109 - # bandwidth for all disks = auto
110 - # operations for all disks = auto
111 - # merged operations for all disks = auto
112 - # i/o time for all disks = auto
113 - # queued operations for all disks = auto
114 - # utilization percentage for all disks = auto
115 - # backlog for all disks = auto
116 - # space usage for all disks = auto
117 - # inodes usage for all disks = auto
118 - # filename to monitor = /proc/diskstats
119 - # path to get block device infos = /sys/dev/block/%lu:%lu/%s
120 - # path to get h/w sector size = /sys/block/%s/queue/hw_sector_size
121 - # path to get h/w sector size for partitions = /sys/dev/block/%lu:%lu/subsystem/%s/../queue
122 -/hw_sector_size
123 -
102 + # enable new disks detected at runtime = yes
103 + # performance metrics for physical disks = auto
104 + # performance metrics for virtual disks = auto
105 + # performance metrics for partitions = no
106 + # bandwidth for all disks = auto
107 + # operations for all disks = auto
108 + # merged operations for all disks = auto
109 + # i/o time for all disks = auto
110 + # queued operations for all disks = auto
111 + # utilization percentage for all disks = auto
112 + # backlog for all disks = auto
113 + # bcache for all disks = auto
114 + # bcache priority stats update every = 0
115 + # remove charts of removed disks = yes
116 + # path to get block device = /sys/block/%s
117 + # path to get block device bcache = /sys/block/%s/bcache
118 + # path to get virtual block device = /sys/devices/virtual/block/%s
119 + # path to get block device infos = /sys/dev/block/%lu:%lu/%s
120 + # path to device mapper = /dev/mapper
121 + # path to /dev/disk/by-label = /dev/disk/by-label
122 + # path to /dev/disk/by-id = /dev/disk/by-id
123 + # path to /dev/vx/dsk = /dev/vx/dsk
124 + # name disks by id = no
125 + # preferred disk ids = *
126 + # exclude disks = loop* ram*
127 + # filename to monitor = /proc/diskstats
128 + # performance metrics for disks with major 8 = yes
129 ```
130
131 For each virtual disk, physical disk and partition you will have a section like this:
collectors/proc.plugin/proc_diskstats.c
+25 -3
@@ -11,6 +11,7 @@
11 #define DISK_TYPE_PARTITION 2
12 #define DISK_TYPE_VIRTUAL 3
13
14 +#define DEFAULT_PREFERRED_IDS "*"
15 #define DEFAULT_EXCLUDED_DISKS "loop* ram*"
16
17 static struct disk {
@@ -164,6 +165,7 @@ static int global_enable_new_disks_detected_at_runtime = CONFIG_BOOLEAN_YES,
165 globals_initialized = 0,
166 global_cleanup_removed_disks = 1;
167
168 +static SIMPLE_PATTERN *preferred_ids = NULL;
169 static SIMPLE_PATTERN *excluded_disks = NULL;
170
171 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) {
318 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) {
319 //info("DEVICE-MAPPER ('%s', %lu:%lu): examining directory '%s' (allowed depth %d).", disk, major, minor, path, depth);
320
319 - int found = 0;
321 + int found = 0, preferred = 0;
322 +
323 + char *first_result = mallocz(result_size);
324
325 DIR *dir = opendir(path);
326 if (!dir) {
@@ -394,8 +398,16 @@ static inline int get_disk_name_from_path(const char *path, char *result, size_t
398 //info("DEVICE-MAPPER ('%s', %lu:%lu): filename '%s' matches.", disk, major, minor, filename);
399
400 snprintfz(result, result_size - 1, "%s%s%s", (prefix)?prefix:"", (prefix)?"_":"", de->d_name);
397 - found = 1;
398 - break;
401 +
402 + if(!found) {
403 + strncpyz(first_result, result, result_size);
404 + found = 1;
405 + }
406 +
407 + if(simple_pattern_matches(preferred_ids, result)) {
408 + preferred = 1;
409 + break;
410 + }
411 }
412 }
413 closedir(dir);
@@ -405,6 +417,10 @@ failed:
417
418 if(!found)
419 result[0] = '\0';
420 + else if(!preferred)
421 + strncpyz(result, first_result, result_size);
422 +
423 + freez(first_result);
424
425 return found;
426 }
@@ -835,6 +851,12 @@ int do_proc_diskstats(int update_every, usec_t dt) {
851
852 name_disks_by_id = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_DISKSTATS, "name disks by id", name_disks_by_id);
853
854 + preferred_ids = simple_pattern_create(
855 + config_get(CONFIG_SECTION_PLUGIN_PROC_DISKSTATS, "preferred disk ids", DEFAULT_PREFERRED_IDS)
856 + , NULL
857 + , SIMPLE_PATTERN_EXACT
858 + );
859 +
860 excluded_disks = simple_pattern_create(
861 config_get(CONFIG_SECTION_PLUGIN_PROC_DISKSTATS, "exclude disks", DEFAULT_EXCLUDED_DISKS)
862 , NULL