]> arthur.barton.de Git - netdata.git/blobdiff - src/plugin_proc.c
dns_query_time plugin: replace "." with "_" in dimensions
[netdata.git] / src / plugin_proc.c
index f32d1fc6fa8d4bf32c9b1ced72be91f4826b1562..b901b0731191294e9fda348528d9b2c0d07f0980 100644 (file)
@@ -7,7 +7,6 @@ static struct proc_module {
     int enabled;
 
     int (*func)(int update_every, usec_t dt);
-    usec_t last_run_usec;
     usec_t duration;
 
     RRDDIM *rd;
@@ -29,6 +28,7 @@ static struct proc_module {
         { .name = "/proc/meminfo", .dim = "meminfo", .func = do_proc_meminfo },
         { .name = "/sys/kernel/mm/ksm", .dim = "ksm", .func = do_sys_kernel_mm_ksm },
         { .name = "/sys/devices/system/edac/mc", .dim = "ecc", .func = do_proc_sys_devices_system_edac_mc },
+        { .name = "/sys/devices/system/node", .dim = "numa", .func = do_proc_sys_devices_system_node },
 
         // network metrics
         { .name = "/proc/net/dev", .dim = "netdev", .func = do_proc_net_dev },
@@ -49,6 +49,9 @@ static struct proc_module {
         { .name = "/proc/net/rpc/nfsd", .dim = "nfsd", .func = do_proc_net_rpc_nfsd },
         { .name = "/proc/net/rpc/nfs", .dim = "nfs", .func = do_proc_net_rpc_nfs },
 
+        // ZFS metrics
+        { .name = "/proc/spl/kstat/zfs/arcstats", .dim = "zfs_arcstats", .func = do_proc_spl_kstat_zfs_arcstats },
+
         // IPC metrics
         { .name = "ipc", .dim = "ipc", .func = do_ipc },
 
@@ -56,9 +59,8 @@ static struct proc_module {
         { .name = NULL, .dim = NULL, .func = NULL }
 };
 
-void *proc_main(void *ptr)
-{
-    (void)ptr;
+void *proc_main(void *ptr) {
+    struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
 
     info("PROC Plugin thread created with task id %d", gettid());
 
@@ -68,46 +70,39 @@ void *proc_main(void *ptr)
     if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
         error("Cannot set pthread cancel state to ENABLE.");
 
-    // disable (by default) various interface that are not needed
-    config_get_boolean("plugin:proc:/proc/net/dev:lo", "enabled", 0);
-    config_get_boolean("plugin:proc:/proc/net/dev:fireqos_monitor", "enabled", 0);
-
-    // when ZERO, attempt to do it
-    int vdo_cpu_netdata             = !config_get_boolean("plugin:proc", "netdata server resources", 1);
+    int vdo_cpu_netdata = config_get_boolean("plugin:proc", "netdata server resources", 1);
 
     // check the enabled status for each module
     int i;
     for(i = 0 ; proc_modules[i].name ;i++) {
-        proc_modules[i].enabled = config_get_boolean("plugin:proc", proc_modules[i].name, 1);
-        proc_modules[i].last_run_usec = 0ULL;
-        proc_modules[i].duration = 0ULL;
-        proc_modules[i].rd = NULL;
+        struct proc_module *pm = &proc_modules[i];
+
+        pm->enabled = config_get_boolean("plugin:proc", pm->name, 1);
+        pm->duration = 0ULL;
+        pm->rd = NULL;
     }
 
-    usec_t step = rrd_update_every * USEC_PER_SEC;
-    for(;;) {
-        usec_t now = now_monotonic_usec();
-        usec_t next = now - (now % step) + step;
+    usec_t step = localhost->rrd_update_every * USEC_PER_SEC;
+    heartbeat_t hb;
+    heartbeat_init(&hb);
 
-        while(now < next) {
-            sleep_usec(next - now);
-            now = now_monotonic_usec();
-        }
+    for(;;) {
+        usec_t hb_dt = heartbeat_next(&hb, step);
+        usec_t duration = 0ULL;
 
         if(unlikely(netdata_exit)) break;
 
         // BEGIN -- the job to be done
 
         for(i = 0 ; proc_modules[i].name ;i++) {
-            if(unlikely(!proc_modules[i].enabled)) continue;
-
-            debug(D_PROCNETDEV_LOOP, "PROC calling %s.", proc_modules[i].name);
+            struct proc_module *pm = &proc_modules[i];
+            if(unlikely(!pm->enabled)) continue;
 
-            proc_modules[i].enabled = !proc_modules[i].func(rrd_update_every, (proc_modules[i].last_run_usec > 0)?now - proc_modules[i].last_run_usec:0ULL);
-            proc_modules[i].last_run_usec = now;
+            debug(D_PROCNETDEV_LOOP, "PROC calling %s.", pm->name);
 
-            now = now_monotonic_usec();
-            proc_modules[i].duration = now - proc_modules[i].last_run_usec;
+            pm->enabled = !pm->func(localhost->rrd_update_every, hb_dt);
+            pm->duration = heartbeat_dt_usec(&hb) - duration;
+            duration += pm->duration;
 
             if(unlikely(netdata_exit)) break;
         }
@@ -116,25 +111,32 @@ void *proc_main(void *ptr)
 
         // --------------------------------------------------------------------
 
-        if(!vdo_cpu_netdata) {
+        if(vdo_cpu_netdata) {
             static RRDSET *st = NULL;
+
             if(unlikely(!st)) {
-                st = rrdset_find_bytype("netdata", "plugin_proc_modules");
+                st = rrdset_find_bytype_localhost("netdata", "plugin_proc_modules");
 
                 if(!st) {
-                    st = rrdset_create("netdata", "plugin_proc_modules", NULL, "proc.internal", NULL, "NetData Proc Plugin Modules Durations", "milliseconds/s", 132001, rrd_update_every, RRDSET_TYPE_STACKED);
+                    st = rrdset_create_localhost("netdata", "plugin_proc_modules", NULL, "proc", NULL
+                                                 , "NetData Proc Plugin Modules Durations", "milliseconds/run", 132001
+                                                 , localhost->rrd_update_every, RRDSET_TYPE_STACKED);
 
                     for(i = 0 ; proc_modules[i].name ;i++) {
-                        if(unlikely(!proc_modules[i].enabled)) continue;
-                        proc_modules[i].rd = rrddim_add(st, proc_modules[i].dim, NULL, 1, 1000, RRDDIM_ABSOLUTE);
+                        struct proc_module *pm = &proc_modules[i];
+                        if(unlikely(!pm->enabled)) continue;
+
+                        pm->rd = rrddim_add(st, pm->dim, NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
                     }
                 }
             }
             else rrdset_next(st);
 
             for(i = 0 ; proc_modules[i].name ;i++) {
-                if(unlikely(!proc_modules[i].enabled)) continue;
-                rrddim_set_by_pointer(st, proc_modules[i].rd, proc_modules[i].duration);
+                struct proc_module *pm = &proc_modules[i];
+                if(unlikely(!pm->enabled)) continue;
+
+                rrddim_set_by_pointer(st, pm->rd, pm->duration);
             }
             rrdset_done(st);
 
@@ -145,6 +147,41 @@ void *proc_main(void *ptr)
 
     info("PROC thread exiting");
 
+    static_thread->enabled = 0;
     pthread_exit(NULL);
     return NULL;
 }
+
+int get_numa_node_count(void)
+{
+    static int numa_node_count = -1;
+
+    if (numa_node_count != -1)
+        return numa_node_count;
+
+    numa_node_count = 0;
+
+    char name[FILENAME_MAX + 1];
+    snprintfz(name, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/devices/system/node");
+    char *dirname = config_get("plugin:proc:/sys/devices/system/node", "directory to monitor", name);
+
+    DIR *dir = opendir(dirname);
+    if(dir) {
+        struct dirent *de = NULL;
+        while((de = readdir(dir))) {
+            if(de->d_type != DT_DIR)
+                continue;
+
+            if(strncmp(de->d_name, "node", 4) != 0)
+                continue;
+
+            if(!isdigit(de->d_name[4]))
+                continue;
+
+            numa_node_count++;
+        }
+        closedir(dir);
+    }
+
+    return numa_node_count;
+}