]> arthur.barton.de Git - netdata.git/blobdiff - src/plugin_proc_diskspace.c
Merge pull request #1597 from l2isbad/some_minor_fixes
[netdata.git] / src / plugin_proc_diskspace.c
index 581c6c6df459a2e9a3b6492f8be0536ac463c1e9..7043385994f84b6137d1cbfae4fdf643d8d261d5 100644 (file)
@@ -1,6 +1,6 @@
 #include "common.h"
 
-#define DELAULT_EXLUDED_PATHS "/proc/ /sys/ /var/run/user/ /run/user/"
+#define DELAULT_EXLUDED_PATHS "/proc/* /sys/* /var/run/user/* /run/user/*"
 
 static struct mountinfo *disk_mountinfo_root = NULL;
 static int check_for_new_mountpoints_every = 15;
@@ -14,7 +14,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();
+        disk_mountinfo_root = mountinfo_read(1);
 
         last_loaded = now;
     }
@@ -25,7 +25,6 @@ static inline void mountinfo_reload(int force) {
 struct mount_point_metadata {
     int do_space;
     int do_inodes;
-    int update_every;
 };
 
 static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
@@ -33,24 +32,23 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
     const char *disk = mi->persistent_id;
 
     static DICTIONARY *mount_points = NULL;
-    static NETDATA_SIMPLE_PATTERN *excluded_mountpoints = NULL;
+    static SIMPLE_PATTERN *excluded_mountpoints = 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")) {
             // the config exists in the old section
             s = config_get("plugin:proc:/proc/diskstats", "exclude space metrics on paths", DELAULT_EXLUDED_PATHS);
-
-            // set it to the new section
-            config_set("plugin:proc:diskspace", "exclude space metrics on paths", s);
+            mode = SIMPLE_PATTERN_PREFIX;
         }
         else
             s = config_get("plugin:proc:diskspace", "exclude space metrics on paths", DELAULT_EXLUDED_PATHS);
 
         mount_points = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
-        excluded_mountpoints = netdata_simple_pattern_list_create(s, NETDATA_SIMPLE_PATTERN_MODE_PREFIX);
+        excluded_mountpoints = simple_pattern_create(s, mode);
     }
 
     struct mount_point_metadata *m = dictionary_get(mount_points, mi->mount_point);
@@ -61,7 +59,7 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
         int def_space = config_get_boolean_ondemand("plugin:proc:diskspace", "space usage for all disks", CONFIG_ONDEMAND_ONDEMAND);
         int def_inodes = config_get_boolean_ondemand("plugin:proc:diskspace", "inodes usage for all disks", CONFIG_ONDEMAND_ONDEMAND);
 
-        if(unlikely(netdata_simple_pattern_list_matches(excluded_mountpoints, mi->mount_point))) {
+        if(unlikely(simple_pattern_matches(excluded_mountpoints, mi->mount_point))) {
             def_space = CONFIG_ONDEMAND_NO;
             def_inodes = CONFIG_ONDEMAND_NO;
         }
@@ -71,8 +69,7 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
 
         struct mount_point_metadata mp = {
                 .do_space = do_space,
-                .do_inodes = do_inodes,
-                .update_every = rrd_update_every
+                .do_inodes = do_inodes
         };
 
         dictionary_set(mount_points, mi->mount_point, &mp, sizeof(struct mount_point_metadata));
@@ -80,7 +77,6 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
     else {
         do_space = m->do_space;
         do_inodes = m->do_inodes;
-        update_every = m->update_every;
     }
 
     if(unlikely(do_space == CONFIG_ONDEMAND_NO && do_inodes == CONFIG_ONDEMAND_NO))
@@ -179,6 +175,8 @@ void *proc_diskspace_main(void *ptr) {
     if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
         error("Cannot set pthread cancel state to ENABLE.");
 
+    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", rrd_update_every);
     if(update_every < rrd_update_every)
         update_every = rrd_update_every;
@@ -187,23 +185,34 @@ void *proc_diskspace_main(void *ptr) {
     if(check_for_new_mountpoints_every < update_every)
         check_for_new_mountpoints_every = update_every;
 
+    RRDSET *stcpu_thread = NULL, *st_duration = NULL;
+    RRDDIM *rd_user = NULL, *rd_system = NULL, *rd_duration = NULL;
+    struct rusage thread;
+
+    usec_t last = 0, dt = 0;
     usec_t step = update_every * USEC_PER_SEC;
     for(;;) {
         usec_t now = now_monotonic_usec();
         usec_t next = now - (now % step) + step;
 
+        dt = (last)?now - last:0;
+
         while(now < next) {
             sleep_usec(next - now);
             now = now_monotonic_usec();
         }
 
+        last = now;
+
         if(unlikely(netdata_exit)) break;
 
+
         // --------------------------------------------------------------------------
         // this is smart enough not to reload it every time
 
         mountinfo_reload(0);
 
+
         // --------------------------------------------------------------------------
         // disk space metrics
 
@@ -216,13 +225,57 @@ void *proc_diskspace_main(void *ptr) {
                 continue;
 
             do_disk_space_stats(mi, update_every);
+            if(unlikely(netdata_exit)) break;
+        }
+
+        if(unlikely(netdata_exit)) break;
+
+        if(vdo_cpu_netdata) {
+            // ----------------------------------------------------------------
+
+            getrusage(RUSAGE_THREAD, &thread);
+
+            if(!stcpu_thread) {
+                stcpu_thread = rrdset_find("netdata.plugin_diskspace");
+                if(!stcpu_thread) stcpu_thread = rrdset_create("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, RRDDIM_INCREMENTAL);
+                rd_system = rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRDDIM_INCREMENTAL);
+            }
+            else
+                rrdset_next(stcpu_thread);
+
+            rrddim_set_by_pointer(stcpu_thread, rd_user, thread.ru_utime.tv_sec * 1000000ULL + thread.ru_utime.tv_usec);
+            rrddim_set_by_pointer(stcpu_thread, rd_system, thread.ru_stime.tv_sec * 1000000ULL + thread.ru_stime.tv_usec);
+            rrdset_done(stcpu_thread);
+
+            // ----------------------------------------------------------------
+
+            if(!st_duration) {
+                st_duration = rrdset_find("netdata.plugin_diskspace_dt");
+                if(!st_duration) st_duration = rrdset_create("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, RRDDIM_ABSOLUTE);
+            }
+            else
+                rrdset_next(st_duration);
+
+            rrddim_set_by_pointer(st_duration, rd_duration, dt);
+            rrdset_done(st_duration);
+
+            // ----------------------------------------------------------------
+
+            if(unlikely(netdata_exit)) break;
         }
     }
 
     info("DISKSPACE thread exiting");
 
     static_thread->enabled = 0;
-    static_thread->thread = NULL;
     pthread_exit(NULL);
     return NULL;
 }