From f2a5d9e50e084dd71aab8b83e3b35b5d1e70c3fd Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Sat, 14 Jan 2017 16:40:20 +0200 Subject: [PATCH] added diskspace plugin monitoring charts --- src/global_statistics.c | 2 +- src/plugin_proc.c | 2 +- src/plugin_proc_diskspace.c | 62 +++++++++++++++++++++++++++++++++++++ src/sys_fs_cgroup.c | 2 +- 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/global_statistics.c b/src/global_statistics.c index bb2b1f08..a698615f 100644 --- a/src/global_statistics.c +++ b/src/global_statistics.c @@ -131,7 +131,7 @@ void global_statistics_charts(void) { if (!stcpu_thread) stcpu_thread = rrdset_find("netdata.plugin_proc_cpu"); if (!stcpu_thread) { - stcpu_thread = rrdset_create("netdata", "plugin_proc_cpu", NULL, "proc.internal", NULL, + stcpu_thread = rrdset_create("netdata", "plugin_proc_cpu", NULL, "proc", NULL, "NetData Proc Plugin CPU usage", "milliseconds/s", 132000, rrd_update_every, RRDSET_TYPE_STACKED); diff --git a/src/plugin_proc.c b/src/plugin_proc.c index e20cbd36..97276431 100644 --- a/src/plugin_proc.c +++ b/src/plugin_proc.c @@ -116,7 +116,7 @@ void *proc_main(void *ptr) { st = rrdset_find_bytype("netdata", "plugin_proc_modules"); if(!st) { - st = rrdset_create("netdata", "plugin_proc_modules", NULL, "proc.internal", NULL, "NetData Proc Plugin Modules Durations", "milliseconds/run", 132001, rrd_update_every, RRDSET_TYPE_STACKED); + st = rrdset_create("netdata", "plugin_proc_modules", NULL, "proc", NULL, "NetData Proc Plugin Modules Durations", "milliseconds/run", 132001, rrd_update_every, RRDSET_TYPE_STACKED); for(i = 0 ; proc_modules[i].name ;i++) { if(unlikely(!proc_modules[i].enabled)) continue; diff --git a/src/plugin_proc_diskspace.c b/src/plugin_proc_diskspace.c index 8ca5dd25..d2795d10 100644 --- a/src/plugin_proc_diskspace.c +++ b/src/plugin_proc_diskspace.c @@ -176,6 +176,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; @@ -184,23 +186,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 @@ -213,6 +226,55 @@ 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; } } diff --git a/src/sys_fs_cgroup.c b/src/sys_fs_cgroup.c index 2274c3f3..5ee9d235 100644 --- a/src/sys_fs_cgroup.c +++ b/src/sys_fs_cgroup.c @@ -1485,7 +1485,7 @@ void *cgroups_main(void *ptr) { if(!stcpu_thread) stcpu_thread = rrdset_find("netdata.plugin_cgroups_cpu"); if(!stcpu_thread) { - stcpu_thread = rrdset_create("netdata", "plugin_cgroups_cpu", NULL, "proc.internal", NULL, "NetData CGroups Plugin CPU usage", "milliseconds/s", 132000, rrd_update_every, RRDSET_TYPE_STACKED); + stcpu_thread = rrdset_create("netdata", "plugin_cgroups_cpu", NULL, "cgroups", NULL, "NetData CGroups Plugin CPU usage", "milliseconds/s", 132000, rrd_update_every, RRDSET_TYPE_STACKED); rrddim_add(stcpu_thread, "user", NULL, 1, 1000, RRDDIM_INCREMENTAL); rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRDDIM_INCREMENTAL); -- 2.39.2