From 58b482856cf37b0519e516ab8dc1105ba958f8b2 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 26 Apr 2019 18:22:17 +0200 Subject: Adding upstream version 1.14.0. Signed-off-by: Daniel Baumann --- collectors/proc.plugin/proc_diskstats.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'collectors/proc.plugin/proc_diskstats.c') diff --git a/collectors/proc.plugin/proc_diskstats.c b/collectors/proc.plugin/proc_diskstats.c index 7e8bee1e7..cd467948c 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 -- cgit v1.2.3