]> arthur.barton.de Git - netdata.git/commitdiff
do not statvfs() dummy filesystems; do not statvfs() excluded mount points; do not...
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 24 Feb 2017 20:09:36 +0000 (22:09 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 24 Feb 2017 20:09:36 +0000 (22:09 +0200)
src/plugin_proc_diskspace.c
src/proc_self_mountinfo.c
src/simple_pattern.c

index 6bb03d1e173c832d19cd0687c3e8f85604ae87a4..db7aa08f99a9b2a8055ba23fa0a76d1aa7d7914e 100644 (file)
@@ -1,6 +1,8 @@
 #include "common.h"
 
 #define DELAULT_EXLUDED_PATHS "/proc/* /sys/* /var/run/user/* /run/user/*"
+#define DEFAULT_EXCLUDED_FILESYSTEMS ""
+#define CONFIG_SECTION_DISKSPACE "plugin:proc:diskspace"
 
 static struct mountinfo *disk_mountinfo_root = NULL;
 static int check_for_new_mountpoints_every = 15;
@@ -14,7 +16,7 @@ static inline void mountinfo_reload(int force) {
         mountinfo_free(disk_mountinfo_root);
 
         // re-read mountinfo in case something changed
-        disk_mountinfo_root = mountinfo_read(1);
+        disk_mountinfo_root = mountinfo_read(0);
 
         last_loaded = now;
     }
@@ -45,22 +47,29 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
 
     static DICTIONARY *mount_points = NULL;
     static SIMPLE_PATTERN *excluded_mountpoints = NULL;
+    static SIMPLE_PATTERN *excluded_filesystems = NULL;
     int do_space, do_inodes;
 
     if(unlikely(!mount_points)) {
-        const char *s;
         SIMPLE_PREFIX_MODE mode = SIMPLE_PATTERN_EXACT;
 
-        if(config_exists("plugin:proc:/proc/diskstats", "exclude space metrics on paths") && !config_exists("plugin:proc:diskspace", "exclude space metrics on paths")) {
+        if(config_exists("plugin:proc:/proc/diskstats", "exclude space metrics on paths") && !config_exists(CONFIG_SECTION_DISKSPACE, "exclude space metrics on paths")) {
             // the config exists in the old section
-            s = config_get("plugin:proc:/proc/diskstats", "exclude space metrics on paths", DELAULT_EXLUDED_PATHS);
+            config_move("plugin:proc:/proc/diskstats", "exclude space metrics on paths", CONFIG_SECTION_DISKSPACE, "exclude space metrics on paths");
             mode = SIMPLE_PATTERN_PREFIX;
         }
-        else
-            s = config_get("plugin:proc:diskspace", "exclude space metrics on paths", DELAULT_EXLUDED_PATHS);
+
+        excluded_mountpoints = simple_pattern_create(
+                config_get(CONFIG_SECTION_DISKSPACE, "exclude space metrics on paths", DELAULT_EXLUDED_PATHS),
+                mode
+        );
+
+        excluded_filesystems = simple_pattern_create(
+                config_get(CONFIG_SECTION_DISKSPACE, "exclude space metrics on filesystems", DEFAULT_EXCLUDED_FILESYSTEMS),
+                SIMPLE_PATTERN_EXACT
+        );
 
         mount_points = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
-        excluded_mountpoints = simple_pattern_create(s, mode);
     }
 
     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) {
         char var_name[4096 + 1];
         snprintfz(var_name, 4096, "plugin:proc:diskspace:%s", mi->mount_point);
 
-        int def_space = config_get_boolean_ondemand("plugin:proc:diskspace", "space usage for all disks", CONFIG_BOOLEAN_AUTO);
-        int def_inodes = config_get_boolean_ondemand("plugin:proc:diskspace", "inodes usage for all disks", CONFIG_BOOLEAN_AUTO);
+        int def_space = config_get_boolean_ondemand(CONFIG_SECTION_DISKSPACE, "space usage for all disks", CONFIG_BOOLEAN_AUTO);
+        int def_inodes = config_get_boolean_ondemand(CONFIG_SECTION_DISKSPACE, "inodes usage for all disks", CONFIG_BOOLEAN_AUTO);
 
         if(unlikely(simple_pattern_matches(excluded_mountpoints, mi->mount_point))) {
             def_space = CONFIG_BOOLEAN_NO;
             def_inodes = CONFIG_BOOLEAN_NO;
         }
 
+        if(unlikely(simple_pattern_matches(excluded_filesystems, mi->filesystem))) {
+            def_space = CONFIG_BOOLEAN_NO;
+            def_inodes = CONFIG_BOOLEAN_NO;
+        }
+
         do_space = config_get_boolean_ondemand(var_name, "space usage", def_space);
         do_inodes = config_get_boolean_ondemand(var_name, "inodes usage", def_inodes);
 
@@ -157,13 +171,23 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
             if(unlikely(!m->st_space)) {
                 char title[4096 + 1];
                 snprintfz(title, 4096, "Disk Space Usage for %s [%s]", family, mi->mount_source);
-                m->st_space = rrdset_create_localhost("disk_space", disk, NULL, family, "disk.space", title, "GB", 2023
-                                                      , update_every, RRDSET_TYPE_STACKED);
+                m->st_space = rrdset_create_localhost(
+                        "disk_space"
+                        , disk
+                        , NULL
+                        , family
+                        , "disk.space"
+                        , title
+                        , "GB"
+                        , 2023
+                        , update_every
+                        , RRDSET_TYPE_STACKED
+                );
             }
 
-            m->rd_space_avail    = rrddim_add(m->st_space, "avail", NULL, bsize, 1024 * 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
-            m->rd_space_used     = rrddim_add(m->st_space, "used", NULL, bsize, 1024 * 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
-            m->rd_space_reserved = rrddim_add(m->st_space, "reserved_for_root", "reserved for root", bsize, 1024 * 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
+            m->rd_space_avail    = rrddim_add(m->st_space, "avail", NULL, (collected_number)bsize, 1024 * 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
+            m->rd_space_used     = rrddim_add(m->st_space, "used", NULL, (collected_number)bsize, 1024 * 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
+            m->rd_space_reserved = rrddim_add(m->st_space, "reserved_for_root", "reserved for root", (collected_number)bsize, 1024 * 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
         }
         else
             rrdset_next(m->st_space);
@@ -185,8 +209,18 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
             if(unlikely(!m->st_inodes)) {
                 char title[4096 + 1];
                 snprintfz(title, 4096, "Disk Files (inodes) Usage for %s [%s]", family, mi->mount_source);
-                m->st_inodes = rrdset_create_localhost("disk_inodes", disk, NULL, family, "disk.inodes", title, "Inodes"
-                                                       , 2024, update_every, RRDSET_TYPE_STACKED);
+                m->st_inodes = rrdset_create_localhost(
+                        "disk_inodes"
+                        , disk
+                        , NULL
+                        , family
+                        , "disk.inodes"
+                        , title
+                        , "Inodes"
+                        , 2024
+                        , update_every
+                        , RRDSET_TYPE_STACKED
+                );
             }
 
             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) {
 
     int vdo_cpu_netdata = config_get_boolean("plugin:proc", "netdata server resources", 1);
 
-    int update_every = (int)config_get_number("plugin:proc:diskspace", "update every", localhost->rrd_update_every);
+    int update_every = (int)config_get_number(CONFIG_SECTION_DISKSPACE, "update every", localhost->rrd_update_every);
     if(update_every < localhost->rrd_update_every)
         update_every = localhost->rrd_update_every;
 
-    check_for_new_mountpoints_every = (int)config_get_number("plugin:proc:diskspace", "check for new mount points every", check_for_new_mountpoints_every);
+    check_for_new_mountpoints_every = (int)config_get_number(CONFIG_SECTION_DISKSPACE, "check for new mount points every", check_for_new_mountpoints_every);
     if(check_for_new_mountpoints_every < update_every)
         check_for_new_mountpoints_every = update_every;
 
@@ -275,11 +309,19 @@ void *proc_diskspace_main(void *ptr) {
 
             if(!stcpu_thread) {
                 stcpu_thread = rrdset_find_localhost("netdata.plugin_diskspace");
-                if(!stcpu_thread) stcpu_thread = rrdset_create_localhost("netdata", "plugin_diskspace", NULL
-                                                                         , "diskspace", NULL
-                                                                         , "NetData Disk Space Plugin CPU usage"
-                                                                         , "milliseconds/s", 132020
-                                                                         , update_every, RRDSET_TYPE_STACKED);
+                if(!stcpu_thread)
+                    stcpu_thread = rrdset_create_localhost(
+                            "netdata"
+                            , "plugin_diskspace"
+                            , NULL
+                            , "diskspace"
+                            , NULL
+                            , "NetData Disk Space Plugin CPU usage"
+                            , "milliseconds/s"
+                            , 132020
+                            , update_every
+                            , RRDSET_TYPE_STACKED
+                    );
 
                 rd_user   = rrddim_add(stcpu_thread, "user", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL);
                 rd_system = rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL);
@@ -295,11 +337,19 @@ void *proc_diskspace_main(void *ptr) {
 
             if(!st_duration) {
                 st_duration = rrdset_find_localhost("netdata.plugin_diskspace_dt");
-                if(!st_duration) st_duration = rrdset_create_localhost("netdata", "plugin_diskspace_dt", NULL
-                                                                       , "diskspace", NULL
-                                                                       , "NetData Disk Space Plugin Duration"
-                                                                       , "milliseconds/run", 132021
-                                                                       , update_every, RRDSET_TYPE_AREA);
+                if(!st_duration)
+                    st_duration = rrdset_create_localhost(
+                            "netdata"
+                            , "plugin_diskspace_dt"
+                            , NULL
+                            , "diskspace"
+                            , NULL
+                            , "NetData Disk Space Plugin Duration"
+                            , "milliseconds/run"
+                            , 132021
+                            , update_every
+                            , RRDSET_TYPE_AREA
+                    );
 
                 rd_duration = rrddim_add(st_duration, "duration", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
             }
index 780c2af7af60b6e52932387667cb7dab4ac5e128..bb031a9ab40e808b0c8f26082806ac48cd5e6b9c 100644 (file)
@@ -293,7 +293,7 @@ struct mountinfo *mountinfo_read(int do_statvfs) {
 
                     struct mountinfo *mt;
                     for(mt = root; mt; mt = mt->next) {
-                        if(unlikely(mt->st_dev == mi->st_dev && !(mi->flags & MOUNTINFO_NO_STAT))) {
+                        if(unlikely(mt->st_dev == mi->st_dev && !(mt->flags & MOUNTINFO_IS_SAME_DEV))) {
                             if(strlen(mi->mount_point) < strlen(mt->mount_point))
                                 mt->flags |= MOUNTINFO_IS_SAME_DEV;
                             else
@@ -319,7 +319,7 @@ struct mountinfo *mountinfo_read(int do_statvfs) {
         }
 
         // check if it has size
-        if(do_statvfs) {
+        if(do_statvfs && !(mi->flags & MOUNTINFO_IS_DUMMY)) {
             struct statvfs buff_statvfs;
             if(unlikely(statvfs(mi->mount_point, &buff_statvfs) < 0)) {
                 mi->flags |= MOUNTINFO_NO_STAT;
index 85215f152747df6e190a4c8df3fba8676dffb9ea..f72a42d06e6e53c01eb3e5d4cd76637d728bd902 100644 (file)
@@ -169,7 +169,7 @@ static inline int match_pattern(struct simple_pattern *m, const char *str, size_
 int simple_pattern_matches(SIMPLE_PATTERN *list, const char *str) {
     struct simple_pattern *m, *root = (struct simple_pattern *)list;
 
-    if(unlikely(!root)) return 0;
+    if(unlikely(!root || !str || !*str)) return 0;
 
     size_t len = strlen(str);
     for(m = root; m ; m = m->next)