@cryptotaxi247 / netdata-1 / commits / f2e430eb7

do not statvfs() dummy filesystems; do not statvfs() excluded mount points; do not statvfs() excluded filesystems; fixes #1834

Costa Tsaousis (ktsaou) committed Feb 24, 2017 at 22:09 UTC f2e430eb7593bf46465865b73ea5ada2066994f8
3 files changed +81 -31
src/plugin_proc_diskspace.c
+78 -28
@@ -1,6 +1,8 @@
1 #include "common.h"
2
3 #define DELAULT_EXLUDED_PATHS "/proc/* /sys/* /var/run/user/* /run/user/*"
4 +#define DEFAULT_EXCLUDED_FILESYSTEMS ""
5 +#define CONFIG_SECTION_DISKSPACE "plugin:proc:diskspace"
6
7 static struct mountinfo *disk_mountinfo_root = NULL;
8 static int check_for_new_mountpoints_every = 15;
@@ -14,7 +16,7 @@ static inline void mountinfo_reload(int force) {
16 mountinfo_free(disk_mountinfo_root);
17
18 // re-read mountinfo in case something changed
17 - disk_mountinfo_root = mountinfo_read(1);
19 + disk_mountinfo_root = mountinfo_read(0);
20
21 last_loaded = now;
22 }
@@ -45,22 +47,29 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
47
48 static DICTIONARY *mount_points = NULL;
49 static SIMPLE_PATTERN *excluded_mountpoints = NULL;
50 + static SIMPLE_PATTERN *excluded_filesystems = NULL;
51 int do_space, do_inodes;
52
53 if(unlikely(!mount_points)) {
51 - const char *s;
54 SIMPLE_PREFIX_MODE mode = SIMPLE_PATTERN_EXACT;
55
54 - if(config_exists("plugin:proc:/proc/diskstats", "exclude space metrics on paths") && !config_exists("plugin:proc:diskspace", "exclude space metrics on paths")) {
56 + if(config_exists("plugin:proc:/proc/diskstats", "exclude space metrics on paths") && !config_exists(CONFIG_SECTION_DISKSPACE, "exclude space metrics on paths")) {
57 // the config exists in the old section
56 - s = config_get("plugin:proc:/proc/diskstats", "exclude space metrics on paths", DELAULT_EXLUDED_PATHS);
58 + config_move("plugin:proc:/proc/diskstats", "exclude space metrics on paths", CONFIG_SECTION_DISKSPACE, "exclude space metrics on paths");
59 mode = SIMPLE_PATTERN_PREFIX;
60 }
59 - else
60 - s = config_get("plugin:proc:diskspace", "exclude space metrics on paths", DELAULT_EXLUDED_PATHS);
61 +
62 + excluded_mountpoints = simple_pattern_create(
63 + config_get(CONFIG_SECTION_DISKSPACE, "exclude space metrics on paths", DELAULT_EXLUDED_PATHS),
64 + mode
65 + );
66 +
67 + excluded_filesystems = simple_pattern_create(
68 + config_get(CONFIG_SECTION_DISKSPACE, "exclude space metrics on filesystems", DEFAULT_EXCLUDED_FILESYSTEMS),
69 + SIMPLE_PATTERN_EXACT
70 + );
71
72 mount_points = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
63 - excluded_mountpoints = simple_pattern_create(s, mode);
73 }
74
75 struct mount_point_metadata *m = dictionary_get(mount_points, mi->mount_point);
@@ -68,14 +77,19 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
77 char var_name[4096 + 1];
78 snprintfz(var_name, 4096, "plugin:proc:diskspace:%s", mi->mount_point);
79
71 - int def_space = config_get_boolean_ondemand("plugin:proc:diskspace", "space usage for all disks", CONFIG_BOOLEAN_AUTO);
72 - int def_inodes = config_get_boolean_ondemand("plugin:proc:diskspace", "inodes usage for all disks", CONFIG_BOOLEAN_AUTO);
80 + int def_space = config_get_boolean_ondemand(CONFIG_SECTION_DISKSPACE, "space usage for all disks", CONFIG_BOOLEAN_AUTO);
81 + int def_inodes = config_get_boolean_ondemand(CONFIG_SECTION_DISKSPACE, "inodes usage for all disks", CONFIG_BOOLEAN_AUTO);
82
83 if(unlikely(simple_pattern_matches(excluded_mountpoints, mi->mount_point))) {
84 def_space = CONFIG_BOOLEAN_NO;
85 def_inodes = CONFIG_BOOLEAN_NO;
86 }
87
88 + if(unlikely(simple_pattern_matches(excluded_filesystems, mi->filesystem))) {
89 + def_space = CONFIG_BOOLEAN_NO;
90 + def_inodes = CONFIG_BOOLEAN_NO;
91 + }
92 +
93 do_space = config_get_boolean_ondemand(var_name, "space usage", def_space);
94 do_inodes = config_get_boolean_ondemand(var_name, "inodes usage", def_inodes);
95
@@ -157,13 +171,23 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
171 if(unlikely(!m->st_space)) {
172 char title[4096 + 1];
173 snprintfz(title, 4096, "Disk Space Usage for %s [%s]", family, mi->mount_source);
160 - m->st_space = rrdset_create_localhost("disk_space", disk, NULL, family, "disk.space", title, "GB", 2023
161 - , update_every, RRDSET_TYPE_STACKED);
174 + m->st_space = rrdset_create_localhost(
175 + "disk_space"
176 + , disk
177 + , NULL
178 + , family
179 + , "disk.space"
180 + , title
181 + , "GB"
182 + , 2023
183 + , update_every
184 + , RRDSET_TYPE_STACKED
185 + );
186 }
187
164 - m->rd_space_avail = rrddim_add(m->st_space, "avail", NULL, bsize, 1024 * 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
165 - m->rd_space_used = rrddim_add(m->st_space, "used", NULL, bsize, 1024 * 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
166 - m->rd_space_reserved = rrddim_add(m->st_space, "reserved_for_root", "reserved for root", bsize, 1024 * 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
188 + m->rd_space_avail = rrddim_add(m->st_space, "avail", NULL, (collected_number)bsize, 1024 * 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
189 + m->rd_space_used = rrddim_add(m->st_space, "used", NULL, (collected_number)bsize, 1024 * 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
190 + m->rd_space_reserved = rrddim_add(m->st_space, "reserved_for_root", "reserved for root", (collected_number)bsize, 1024 * 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
191 }
192 else
193 rrdset_next(m->st_space);
@@ -185,8 +209,18 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
209 if(unlikely(!m->st_inodes)) {
210 char title[4096 + 1];
211 snprintfz(title, 4096, "Disk Files (inodes) Usage for %s [%s]", family, mi->mount_source);
188 - m->st_inodes = rrdset_create_localhost("disk_inodes", disk, NULL, family, "disk.inodes", title, "Inodes"
189 - , 2024, update_every, RRDSET_TYPE_STACKED);
212 + m->st_inodes = rrdset_create_localhost(
213 + "disk_inodes"
214 + , disk
215 + , NULL
216 + , family
217 + , "disk.inodes"
218 + , title
219 + , "Inodes"
220 + , 2024
221 + , update_every
222 + , RRDSET_TYPE_STACKED
223 + );
224 }
225
226 m->rd_inodes_avail = rrddim_add(m->st_inodes, "avail", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
@@ -223,11 +257,11 @@ void *proc_diskspace_main(void *ptr) {
257
258 int vdo_cpu_netdata = config_get_boolean("plugin:proc", "netdata server resources", 1);
259
226 - int update_every = (int)config_get_number("plugin:proc:diskspace", "update every", localhost->rrd_update_every);
260 + int update_every = (int)config_get_number(CONFIG_SECTION_DISKSPACE, "update every", localhost->rrd_update_every);
261 if(update_every < localhost->rrd_update_every)
262 update_every = localhost->rrd_update_every;
263
230 - check_for_new_mountpoints_every = (int)config_get_number("plugin:proc:diskspace", "check for new mount points every", check_for_new_mountpoints_every);
264 + check_for_new_mountpoints_every = (int)config_get_number(CONFIG_SECTION_DISKSPACE, "check for new mount points every", check_for_new_mountpoints_every);
265 if(check_for_new_mountpoints_every < update_every)
266 check_for_new_mountpoints_every = update_every;
267
@@ -275,11 +309,19 @@ void *proc_diskspace_main(void *ptr) {
309
310 if(!stcpu_thread) {
311 stcpu_thread = rrdset_find_localhost("netdata.plugin_diskspace");
278 - if(!stcpu_thread) stcpu_thread = rrdset_create_localhost("netdata", "plugin_diskspace", NULL
279 - , "diskspace", NULL
280 - , "NetData Disk Space Plugin CPU usage"
281 - , "milliseconds/s", 132020
282 - , update_every, RRDSET_TYPE_STACKED);
312 + if(!stcpu_thread)
313 + stcpu_thread = rrdset_create_localhost(
314 + "netdata"
315 + , "plugin_diskspace"
316 + , NULL
317 + , "diskspace"
318 + , NULL
319 + , "NetData Disk Space Plugin CPU usage"
320 + , "milliseconds/s"
321 + , 132020
322 + , update_every
323 + , RRDSET_TYPE_STACKED
324 + );
325
326 rd_user = rrddim_add(stcpu_thread, "user", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL);
327 rd_system = rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL);
@@ -295,11 +337,19 @@ void *proc_diskspace_main(void *ptr) {
337
338 if(!st_duration) {
339 st_duration = rrdset_find_localhost("netdata.plugin_diskspace_dt");
298 - if(!st_duration) st_duration = rrdset_create_localhost("netdata", "plugin_diskspace_dt", NULL
299 - , "diskspace", NULL
300 - , "NetData Disk Space Plugin Duration"
301 - , "milliseconds/run", 132021
302 - , update_every, RRDSET_TYPE_AREA);
340 + if(!st_duration)
341 + st_duration = rrdset_create_localhost(
342 + "netdata"
343 + , "plugin_diskspace_dt"
344 + , NULL
345 + , "diskspace"
346 + , NULL
347 + , "NetData Disk Space Plugin Duration"
348 + , "milliseconds/run"
349 + , 132021
350 + , update_every
351 + , RRDSET_TYPE_AREA
352 + );
353
354 rd_duration = rrddim_add(st_duration, "duration", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
355 }
src/proc_self_mountinfo.c
+2 -2
@@ -293,7 +293,7 @@ struct mountinfo *mountinfo_read(int do_statvfs) {
293
294 struct mountinfo *mt;
295 for(mt = root; mt; mt = mt->next) {
296 - if(unlikely(mt->st_dev == mi->st_dev && !(mi->flags & MOUNTINFO_NO_STAT))) {
296 + if(unlikely(mt->st_dev == mi->st_dev && !(mt->flags & MOUNTINFO_IS_SAME_DEV))) {
297 if(strlen(mi->mount_point) < strlen(mt->mount_point))
298 mt->flags |= MOUNTINFO_IS_SAME_DEV;
299 else
@@ -319,7 +319,7 @@ struct mountinfo *mountinfo_read(int do_statvfs) {
319 }
320
321 // check if it has size
322 - if(do_statvfs) {
322 + if(do_statvfs && !(mi->flags & MOUNTINFO_IS_DUMMY)) {
323 struct statvfs buff_statvfs;
324 if(unlikely(statvfs(mi->mount_point, &buff_statvfs) < 0)) {
325 mi->flags |= MOUNTINFO_NO_STAT;
src/simple_pattern.c
+1 -1
@@ -169,7 +169,7 @@ static inline int match_pattern(struct simple_pattern *m, const char *str, size_
169 int simple_pattern_matches(SIMPLE_PATTERN *list, const char *str) {
170 struct simple_pattern *m, *root = (struct simple_pattern *)list;
171
172 - if(unlikely(!root)) return 0;
172 + if(unlikely(!root || !str || !*str)) return 0;
173
174 size_t len = strlen(str);
175 for(m = root; m ; m = m->next)