From bf06c2fb046ad56eafecccff26c05d8d24c53dfc Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Sat, 18 Feb 2017 18:28:31 +0200 Subject: [PATCH] each host can have its own settings for history, update_every, rrd memory mode, health enabled --- src/freebsd_sysctl.c | 14 +++++++------- src/global_statistics.c | 14 +++++++------- src/ipc.c | 4 ++-- src/main.c | 24 ++++++++++++------------ src/plugin_checks.c | 12 ++++++------ src/plugin_freebsd.c | 4 ++-- src/plugin_idlejitter.c | 4 ++-- src/plugin_macos.c | 8 ++++---- src/plugin_nfacct.c | 16 ++++++++-------- src/plugin_proc.c | 6 +++--- src/plugin_proc_diskspace.c | 6 +++--- src/plugin_tc.c | 18 +++++++++--------- src/plugins_d.c | 6 +++--- src/registry.c | 6 +++--- src/rrd.c | 4 ++-- src/rrd.h | 8 ++++++-- src/rrd2json.c | 8 ++++---- src/rrdhost.c | 6 ++++-- src/rrdset.c | 2 +- src/sys_fs_cgroup.c | 6 +++--- src/unit_test.c | 4 ++-- src/web_client.c | 4 ++-- 22 files changed, 95 insertions(+), 89 deletions(-) diff --git a/src/freebsd_sysctl.c b/src/freebsd_sysctl.c index 026ad4d3..c01e8973 100644 --- a/src/freebsd_sysctl.c +++ b/src/freebsd_sysctl.c @@ -936,7 +936,7 @@ int do_freebsd_sysctl(int update_every, usec_t dt) { st = rrdset_find_localhost("system.ipc_semaphores"); if (unlikely(!st)) { - st = rrdset_create_localhost("system", "ipc_semaphores", NULL, "ipc semaphores", NULL, "IPC Semaphores", "semaphores", 1000, rrd_update_every, RRDSET_TYPE_AREA); + st = rrdset_create_localhost("system", "ipc_semaphores", NULL, "ipc semaphores", NULL, "IPC Semaphores", "semaphores", 1000, localhost->rrd_update_every, RRDSET_TYPE_AREA); rrddim_add(st, "semaphores", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } else rrdset_next(st); @@ -948,7 +948,7 @@ int do_freebsd_sysctl(int update_every, usec_t dt) { st = rrdset_find_localhost("system.ipc_semaphore_arrays"); if (unlikely(!st)) { - st = rrdset_create_localhost("system", "ipc_semaphore_arrays", NULL, "ipc semaphores", NULL, "IPC Semaphore Arrays", "arrays", 1000, rrd_update_every, RRDSET_TYPE_AREA); + st = rrdset_create_localhost("system", "ipc_semaphore_arrays", NULL, "ipc semaphores", NULL, "IPC Semaphore Arrays", "arrays", 1000, localhost->rrd_update_every, RRDSET_TYPE_AREA); rrddim_add(st, "arrays", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } else rrdset_next(st); @@ -984,7 +984,7 @@ int do_freebsd_sysctl(int update_every, usec_t dt) { st = rrdset_find_localhost("system.ipc_shared_mem_segs"); if (unlikely(!st)) { - st = rrdset_create_localhost("system", "ipc_shared_mem_segs", NULL, "ipc shared memory", NULL, "IPC Shared Memory Segments", "segments", 1000, rrd_update_every, RRDSET_TYPE_AREA); + st = rrdset_create_localhost("system", "ipc_shared_mem_segs", NULL, "ipc shared memory", NULL, "IPC Shared Memory Segments", "segments", 1000, localhost->rrd_update_every, RRDSET_TYPE_AREA); rrddim_add(st, "segments", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } else rrdset_next(st); @@ -996,7 +996,7 @@ int do_freebsd_sysctl(int update_every, usec_t dt) { st = rrdset_find_localhost("system.ipc_shared_mem_size"); if (unlikely(!st)) { - st = rrdset_create_localhost("system", "ipc_shared_mem_size", NULL, "ipc shared memory", NULL, "IPC Shared Memory Segments Size", "kilobytes", 1000, rrd_update_every, RRDSET_TYPE_AREA); + st = rrdset_create_localhost("system", "ipc_shared_mem_size", NULL, "ipc shared memory", NULL, "IPC Shared Memory Segments Size", "kilobytes", 1000, localhost->rrd_update_every, RRDSET_TYPE_AREA); rrddim_add(st, "allocated", NULL, 1, 1024, RRD_ALGORITHM_ABSOLUTE); } else rrdset_next(st); @@ -1036,7 +1036,7 @@ int do_freebsd_sysctl(int update_every, usec_t dt) { st = rrdset_find_localhost("system.ipc_msq_queues"); if (unlikely(!st)) { - st = rrdset_create_localhost("system", "ipc_msq_queues", NULL, "ipc message queues", NULL, "Number of IPC Message Queues", "queues", 990, rrd_update_every, RRDSET_TYPE_AREA); + st = rrdset_create_localhost("system", "ipc_msq_queues", NULL, "ipc message queues", NULL, "Number of IPC Message Queues", "queues", 990, localhost->rrd_update_every, RRDSET_TYPE_AREA); rrddim_add(st, "queues", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } else rrdset_next(st); @@ -1048,7 +1048,7 @@ int do_freebsd_sysctl(int update_every, usec_t dt) { st = rrdset_find_localhost("system.ipc_msq_messages"); if (unlikely(!st)) { - st = rrdset_create_localhost("system", "ipc_msq_messages", NULL, "ipc message queues", NULL, "Number of Messages in IPC Message Queues", "messages", 1000, rrd_update_every, RRDSET_TYPE_AREA); + st = rrdset_create_localhost("system", "ipc_msq_messages", NULL, "ipc message queues", NULL, "Number of Messages in IPC Message Queues", "messages", 1000, localhost->rrd_update_every, RRDSET_TYPE_AREA); rrddim_add(st, "messages", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } else rrdset_next(st); @@ -1060,7 +1060,7 @@ int do_freebsd_sysctl(int update_every, usec_t dt) { st = rrdset_find_localhost("system.ipc_msq_size"); if (unlikely(!st)) { - st = rrdset_create_localhost("system", "ipc_msq_size", NULL, "ipc message queues", NULL, "Size of IPC Message Queues", "bytes", 1100, rrd_update_every, RRDSET_TYPE_LINE); + st = rrdset_create_localhost("system", "ipc_msq_size", NULL, "ipc message queues", NULL, "Size of IPC Message Queues", "bytes", 1100, localhost->rrd_update_every, RRDSET_TYPE_LINE); rrddim_add(st, "allocated", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rrddim_add(st, "used", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } diff --git a/src/global_statistics.c b/src/global_statistics.c index d9868d22..c3d63043 100644 --- a/src/global_statistics.c +++ b/src/global_statistics.c @@ -133,7 +133,7 @@ void global_statistics_charts(void) { if (!stcpu_thread) { stcpu_thread = rrdset_create_localhost("netdata", "plugin_proc_cpu", NULL, "proc", NULL , "NetData Proc Plugin CPU usage", "milliseconds/s", 132000 - , rrd_update_every, RRDSET_TYPE_STACKED); + , localhost->rrd_update_every, RRDSET_TYPE_STACKED); rrddim_add(stcpu_thread, "user", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL); rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL); @@ -148,7 +148,7 @@ void global_statistics_charts(void) { if (!stcpu) stcpu = rrdset_find_localhost("netdata.server_cpu"); if (!stcpu) { stcpu = rrdset_create_localhost("netdata", "server_cpu", NULL, "netdata", NULL, "NetData CPU usage" - , "milliseconds/s", 130000, rrd_update_every, RRDSET_TYPE_STACKED); + , "milliseconds/s", 130000, localhost->rrd_update_every, RRDSET_TYPE_STACKED); rrddim_add(stcpu, "user", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL); rrddim_add(stcpu, "system", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL); @@ -163,7 +163,7 @@ void global_statistics_charts(void) { if (!stclients) stclients = rrdset_find_localhost("netdata.clients"); if (!stclients) { stclients = rrdset_create_localhost("netdata", "clients", NULL, "netdata", NULL, "NetData Web Clients" - , "connected clients", 130200, rrd_update_every, RRDSET_TYPE_LINE); + , "connected clients", 130200, localhost->rrd_update_every, RRDSET_TYPE_LINE); rrddim_add(stclients, "clients", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } else rrdset_next(stclients); @@ -176,7 +176,7 @@ void global_statistics_charts(void) { if (!streqs) streqs = rrdset_find_localhost("netdata.requests"); if (!streqs) { streqs = rrdset_create_localhost("netdata", "requests", NULL, "netdata", NULL, "NetData Web Requests" - , "requests/s", 130300, rrd_update_every, RRDSET_TYPE_LINE); + , "requests/s", 130300, localhost->rrd_update_every, RRDSET_TYPE_LINE); rrddim_add(streqs, "requests", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); } else rrdset_next(streqs); @@ -189,7 +189,7 @@ void global_statistics_charts(void) { if (!stbytes) stbytes = rrdset_find_localhost("netdata.net"); if (!stbytes) { stbytes = rrdset_create_localhost("netdata", "net", NULL, "netdata", NULL, "NetData Network Traffic" - , "kilobits/s", 130000, rrd_update_every, RRDSET_TYPE_AREA); + , "kilobits/s", 130000, localhost->rrd_update_every, RRDSET_TYPE_AREA); rrddim_add(stbytes, "in", NULL, 8, 1024, RRD_ALGORITHM_INCREMENTAL); rrddim_add(stbytes, "out", NULL, -8, 1024, RRD_ALGORITHM_INCREMENTAL); @@ -204,7 +204,7 @@ void global_statistics_charts(void) { if (!stduration) stduration = rrdset_find_localhost("netdata.response_time"); if (!stduration) { stduration = rrdset_create_localhost("netdata", "response_time", NULL, "netdata", NULL - , "NetData API Response Time", "ms/request", 130400, rrd_update_every + , "NetData API Response Time", "ms/request", 130400, localhost->rrd_update_every , RRDSET_TYPE_LINE); rrddim_add(stduration, "average", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); @@ -237,7 +237,7 @@ void global_statistics_charts(void) { if (!stcompression) { stcompression = rrdset_create_localhost("netdata", "compression_ratio", NULL, "netdata", NULL , "NetData API Responses Compression Savings Ratio", "percentage" - , 130500, rrd_update_every, RRDSET_TYPE_LINE); + , 130500, localhost->rrd_update_every, RRDSET_TYPE_LINE); rrddim_add(stcompression, "savings", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); } else rrdset_next(stcompression); diff --git a/src/ipc.c b/src/ipc.c index e4403e04..1dabf5e1 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -194,7 +194,7 @@ int do_ipc(int update_every, usec_t dt) { semaphores = rrdset_find_localhost("system.ipc_semaphores"); if(!semaphores) { semaphores = rrdset_create_localhost("system", "ipc_semaphores", NULL, "ipc semaphores", NULL - , "IPC Semaphores", "semaphores", 1000, rrd_update_every + , "IPC Semaphores", "semaphores", 1000, localhost->rrd_update_every , RRDSET_TYPE_AREA); rrddim_add(semaphores, "semaphores", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } @@ -202,7 +202,7 @@ int do_ipc(int update_every, usec_t dt) { arrays = rrdset_find_localhost("system.ipc_semaphore_arrays"); if(!arrays) { arrays = rrdset_create_localhost("system", "ipc_semaphore_arrays", NULL, "ipc semaphores", NULL - , "IPC Semaphore Arrays", "arrays", 1000, rrd_update_every + , "IPC Semaphore Arrays", "arrays", 1000, localhost->rrd_update_every , RRDSET_TYPE_AREA); rrddim_add(arrays, "arrays", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } diff --git a/src/main.c b/src/main.c index 1100b393..d56af23e 100644 --- a/src/main.c +++ b/src/main.c @@ -443,7 +443,7 @@ int main(int argc, char **argv) { char* stacksize_string = "stacksize="; char* debug_flags_string = "debug_flags="; if(strcmp(optarg, "unittest") == 0) { - rrd_update_every = 1; + default_localhost_rrd_update_every = 1; if(run_all_mockup_tests()) exit(1); if(unit_test_storage()) exit(1); fprintf(stderr, "\n\nALL TESTS PASSED\n\n"); @@ -654,28 +654,28 @@ int main(int argc, char **argv) { // -------------------------------------------------------------------- - rrd_default_history_entries = (int) config_get_number("global", "history", RRD_DEFAULT_HISTORY_ENTRIES); - if(rrd_default_history_entries < 5 || rrd_default_history_entries > RRD_HISTORY_ENTRIES_MAX) { - error("Invalid history entries %d given. Defaulting to %d.", rrd_default_history_entries, RRD_DEFAULT_HISTORY_ENTRIES); - rrd_default_history_entries = RRD_DEFAULT_HISTORY_ENTRIES; + default_localhost_rrd_history_entries = (int) config_get_number("global", "history", RRD_DEFAULT_HISTORY_ENTRIES); + if(default_localhost_rrd_history_entries < 5 || default_localhost_rrd_history_entries > RRD_HISTORY_ENTRIES_MAX) { + error("Invalid history entries %d given. Defaulting to %d.", default_localhost_rrd_history_entries, RRD_DEFAULT_HISTORY_ENTRIES); + default_localhost_rrd_history_entries = RRD_DEFAULT_HISTORY_ENTRIES; } else { - debug(D_OPTIONS, "save lines set to %d.", rrd_default_history_entries); + debug(D_OPTIONS, "save lines set to %d.", default_localhost_rrd_history_entries); } // -------------------------------------------------------------------- - rrd_update_every = (int) config_get_number("global", "update every", UPDATE_EVERY); - if(rrd_update_every < 1 || rrd_update_every > 600) { - error("Invalid data collection frequency (update every) %d given. Defaulting to %d.", rrd_update_every, UPDATE_EVERY_MAX); - rrd_update_every = UPDATE_EVERY; + default_localhost_rrd_update_every = (int) config_get_number("global", "update every", UPDATE_EVERY); + if(default_localhost_rrd_update_every < 1 || default_localhost_rrd_update_every > 600) { + error("Invalid data collection frequency (update every) %d given. Defaulting to %d.", default_localhost_rrd_update_every, UPDATE_EVERY_MAX); + default_localhost_rrd_update_every = UPDATE_EVERY; } - else debug(D_OPTIONS, "update timer set to %d.", rrd_update_every); + else debug(D_OPTIONS, "update timer set to %d.", default_localhost_rrd_update_every); // let the plugins know the min update_every { char buf[16]; - snprintfz(buf, 15, "%d", rrd_update_every); + snprintfz(buf, 15, "%d", default_localhost_rrd_update_every); setenv("NETDATA_UPDATE_EVERY", buf, 1); } diff --git a/src/plugin_checks.c b/src/plugin_checks.c index 52575a66..3a0a83bd 100644 --- a/src/plugin_checks.c +++ b/src/plugin_checks.c @@ -11,23 +11,23 @@ void *checks_main(void *ptr) { if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) error("Cannot set pthread cancel state to ENABLE."); - usec_t usec = 0, susec = rrd_update_every * USEC_PER_SEC, loop_usec = 0, total_susec = 0; + usec_t usec = 0, susec = localhost->rrd_update_every * USEC_PER_SEC, loop_usec = 0, total_susec = 0; struct timeval now, last, loop; RRDSET *check1, *check2, *check3, *apps_cpu = NULL; check1 = rrdset_create_localhost("netdata", "check1", NULL, "netdata", NULL, "Caller gives microseconds" - , "a million !", 99999, rrd_update_every, RRDSET_TYPE_LINE); + , "a million !", 99999, localhost->rrd_update_every, RRDSET_TYPE_LINE); rrddim_add(check1, "absolute", NULL, -1, 1, RRD_ALGORITHM_ABSOLUTE); rrddim_add(check1, "incremental", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); check2 = rrdset_create_localhost("netdata", "check2", NULL, "netdata", NULL, "Netdata calcs microseconds" - , "a million !", 99999, rrd_update_every, RRDSET_TYPE_LINE); + , "a million !", 99999, localhost->rrd_update_every, RRDSET_TYPE_LINE); rrddim_add(check2, "absolute", NULL, -1, 1, RRD_ALGORITHM_ABSOLUTE); rrddim_add(check2, "incremental", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); check3 = rrdset_create_localhost("netdata", "checkdt", NULL, "netdata", NULL, "Clock difference" - , "microseconds diff", 99999, rrd_update_every, RRDSET_TYPE_LINE); + , "microseconds diff", 99999, localhost->rrd_update_every, RRDSET_TYPE_LINE); rrddim_add(check3, "caller", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rrddim_add(check3, "netdata", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rrddim_add(check3, "apps.plugin", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); @@ -42,8 +42,8 @@ void *checks_main(void *ptr) { usec = loop_usec - susec; debug(D_PROCNETDEV_LOOP, "CHECK: last loop took %llu usec (worked for %llu, sleeped for %llu).", loop_usec, usec, susec); - if(usec < (rrd_update_every * USEC_PER_SEC / 2ULL)) susec = (rrd_update_every * USEC_PER_SEC) - usec; - else susec = rrd_update_every * USEC_PER_SEC / 2ULL; + if(usec < (localhost->rrd_update_every * USEC_PER_SEC / 2ULL)) susec = (localhost->rrd_update_every * USEC_PER_SEC) - usec; + else susec = localhost->rrd_update_every * USEC_PER_SEC / 2ULL; // -------------------------------------------------------------------- // Calculate loop time diff --git a/src/plugin_freebsd.c b/src/plugin_freebsd.c index 4fef148a..3490e70e 100644 --- a/src/plugin_freebsd.c +++ b/src/plugin_freebsd.c @@ -18,7 +18,7 @@ void *freebsd_main(void *ptr) { // keep track of the time each module was called unsigned long long sutime_freebsd_sysctl = 0ULL; - usec_t step = rrd_update_every * USEC_PER_SEC; + usec_t step = localhost->rrd_update_every * USEC_PER_SEC; heartbeat_t hb; heartbeat_init(&hb); for(;;) { @@ -30,7 +30,7 @@ void *freebsd_main(void *ptr) { if(!vdo_freebsd_sysctl) { debug(D_PROCNETDEV_LOOP, "FREEBSD: calling do_freebsd_sysctl()."); - vdo_freebsd_sysctl = do_freebsd_sysctl(rrd_update_every, hb_dt); + vdo_freebsd_sysctl = do_freebsd_sysctl(localhost->rrd_update_every, hb_dt); } if(unlikely(netdata_exit)) break; diff --git a/src/plugin_idlejitter.c b/src/plugin_idlejitter.c index bff85d13..66b3b604 100644 --- a/src/plugin_idlejitter.c +++ b/src/plugin_idlejitter.c @@ -22,7 +22,7 @@ void *cpuidlejitter_main(void *ptr) { RRDSET *st = rrdset_find_localhost("system.idlejitter"); if(!st) { st = rrdset_create_localhost("system", "idlejitter", NULL, "processes", NULL, "CPU Idle Jitter" - , "microseconds lost/s", 9999, rrd_update_every, RRDSET_TYPE_LINE); + , "microseconds lost/s", 9999, localhost->rrd_update_every, RRDSET_TYPE_LINE); rrddim_add(st, "jitter", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } @@ -31,7 +31,7 @@ void *cpuidlejitter_main(void *ptr) { for(counter = 0; 1 ;counter++) { usec_t usec = 0, susec = 0; - while(susec < (rrd_update_every * USEC_PER_SEC)) { + while(susec < (localhost->rrd_update_every * USEC_PER_SEC)) { now_monotonic_timeval(&before); sleep_usec(sleep_ms * 1000); diff --git a/src/plugin_macos.c b/src/plugin_macos.c index 54965c5d..4e84a084 100644 --- a/src/plugin_macos.c +++ b/src/plugin_macos.c @@ -22,7 +22,7 @@ void *macos_main(void *ptr) { unsigned long long sutime_macos_mach_smi = 0ULL; unsigned long long sutime_macos_iokit = 0ULL; - usec_t step = rrd_update_every * USEC_PER_SEC; + usec_t step = localhost->rrd_update_every * USEC_PER_SEC; heartbeat_t hb; heartbeat_init(&hb); for(;;) { @@ -34,19 +34,19 @@ void *macos_main(void *ptr) { if(!vdo_macos_sysctl) { debug(D_PROCNETDEV_LOOP, "MACOS: calling do_macos_sysctl()."); - vdo_macos_sysctl = do_macos_sysctl(rrd_update_every, hb_dt); + vdo_macos_sysctl = do_macos_sysctl(localhost->rrd_update_every, hb_dt); } if(unlikely(netdata_exit)) break; if(!vdo_macos_mach_smi) { debug(D_PROCNETDEV_LOOP, "MACOS: calling do_macos_mach_smi()."); - vdo_macos_mach_smi = do_macos_mach_smi(rrd_update_every, hb_dt); + vdo_macos_mach_smi = do_macos_mach_smi(localhost->rrd_update_every, hb_dt); } if(unlikely(netdata_exit)) break; if(!vdo_macos_iokit) { debug(D_PROCNETDEV_LOOP, "MACOS: calling do_macos_iokit()."); - vdo_macos_iokit = do_macos_iokit(rrd_update_every, hb_dt); + vdo_macos_iokit = do_macos_iokit(localhost->rrd_update_every, hb_dt); } if(unlikely(netdata_exit)) break; diff --git a/src/plugin_nfacct.c b/src/plugin_nfacct.c index ca67ec19..5140d7bc 100644 --- a/src/plugin_nfacct.c +++ b/src/plugin_nfacct.c @@ -128,8 +128,8 @@ void *nfacct_main(void *ptr) { usec = dt_usec(&now, &last) - susec; debug(D_NFACCT_LOOP, "nfacct.plugin: last loop took %llu usec (worked for %llu, sleeped for %llu).", usec + susec, usec, susec); - if(usec < (rrd_update_every * 1000000ULL / 2ULL)) susec = (rrd_update_every * 1000000ULL) - usec; - else susec = rrd_update_every * 1000000ULL / 2ULL; + if(usec < (default_localhost_rrd_update_every * 1000000ULL / 2ULL)) susec = (default_localhost_rrd_update_every * 1000000ULL) - usec; + else susec = default_localhost_rrd_update_every * 1000000ULL / 2ULL; // -------------------------------------------------------------------- @@ -139,17 +139,17 @@ void *nfacct_main(void *ptr) { st = rrdset_find_bytype("netfilter", "nfacct_packets"); if(!st) { - st = rrdset_create("netfilter", "nfacct_packets", NULL, "nfacct", NULL, "Netfilter Accounting Packets", "packets/s", 3206, rrd_update_every, RRDSET_TYPE_STACKED); + st = rrdset_create("netfilter", "nfacct_packets", NULL, "nfacct", NULL, "Netfilter Accounting Packets", "packets/s", 3206, default_localhost_rrd_update_every, RRDSET_TYPE_STACKED); for(i = 0; i < nfacct_list->len ; i++) - rrddim_add(st, nfacct_list->data[i].name, NULL, 1, rrd_update_every, RRD_ALGORITHM_INCREMENTAL); + rrddim_add(st, nfacct_list->data[i].name, NULL, 1, default_localhost_rrd_update_every, RRD_ALGORITHM_INCREMENTAL); } else rrdset_next(st); for(i = 0; i < nfacct_list->len ; i++) { RRDDIM *rd = rrddim_find(st, nfacct_list->data[i].name); - if(!rd) rd = rrddim_add(st, nfacct_list->data[i].name, NULL, 1, rrd_update_every, RRD_ALGORITHM_INCREMENTAL); + if(!rd) rd = rrddim_add(st, nfacct_list->data[i].name, NULL, 1, default_localhost_rrd_update_every, RRD_ALGORITHM_INCREMENTAL); if(rd) rrddim_set_by_pointer(st, rd, nfacct_list->data[i].pkts); } @@ -159,17 +159,17 @@ void *nfacct_main(void *ptr) { st = rrdset_find_bytype("netfilter", "nfacct_bytes"); if(!st) { - st = rrdset_create("netfilter", "nfacct_bytes", NULL, "nfacct", NULL, "Netfilter Accounting Bandwidth", "kilobytes/s", 3207, rrd_update_every, RRDSET_TYPE_STACKED); + st = rrdset_create("netfilter", "nfacct_bytes", NULL, "nfacct", NULL, "Netfilter Accounting Bandwidth", "kilobytes/s", 3207, default_localhost_rrd_update_every, RRDSET_TYPE_STACKED); for(i = 0; i < nfacct_list->len ; i++) - rrddim_add(st, nfacct_list->data[i].name, NULL, 1, 1000 * rrd_update_every, RRD_ALGORITHM_INCREMENTAL); + rrddim_add(st, nfacct_list->data[i].name, NULL, 1, 1000 * default_localhost_rrd_update_every, RRD_ALGORITHM_INCREMENTAL); } else rrdset_next(st); for(i = 0; i < nfacct_list->len ; i++) { RRDDIM *rd = rrddim_find(st, nfacct_list->data[i].name); - if(!rd) rd = rrddim_add(st, nfacct_list->data[i].name, NULL, 1, 1000 * rrd_update_every, RRD_ALGORITHM_INCREMENTAL); + if(!rd) rd = rrddim_add(st, nfacct_list->data[i].name, NULL, 1, 1000 * default_localhost_rrd_update_every, RRD_ALGORITHM_INCREMENTAL); if(rd) rrddim_set_by_pointer(st, rd, nfacct_list->data[i].bytes); } diff --git a/src/plugin_proc.c b/src/plugin_proc.c index bc300c27..2ca77491 100644 --- a/src/plugin_proc.c +++ b/src/plugin_proc.c @@ -79,7 +79,7 @@ void *proc_main(void *ptr) { pm->rd = NULL; } - usec_t step = rrd_update_every * USEC_PER_SEC; + usec_t step = localhost->rrd_update_every * USEC_PER_SEC; heartbeat_t hb; heartbeat_init(&hb); @@ -97,7 +97,7 @@ void *proc_main(void *ptr) { debug(D_PROCNETDEV_LOOP, "PROC calling %s.", pm->name); - pm->enabled = !pm->func(rrd_update_every, hb_dt); + pm->enabled = !pm->func(localhost->rrd_update_every, hb_dt); pm->duration = heartbeat_dt_usec(&hb) - duration; duration += pm->duration; @@ -117,7 +117,7 @@ void *proc_main(void *ptr) { if(!st) { st = rrdset_create_localhost("netdata", "plugin_proc_modules", NULL, "proc", NULL , "NetData Proc Plugin Modules Durations", "milliseconds/run", 132001 - , rrd_update_every, RRDSET_TYPE_STACKED); + , localhost->rrd_update_every, RRDSET_TYPE_STACKED); for(i = 0 ; proc_modules[i].name ;i++) { struct proc_module *pm = &proc_modules[i]; diff --git a/src/plugin_proc_diskspace.c b/src/plugin_proc_diskspace.c index 984c0ceb..9e11f85c 100644 --- a/src/plugin_proc_diskspace.c +++ b/src/plugin_proc_diskspace.c @@ -223,9 +223,9 @@ 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", rrd_update_every); - if(update_every < rrd_update_every) - update_every = rrd_update_every; + int update_every = (int)config_get_number("plugin:proc: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); if(check_for_new_mountpoints_every < update_every) diff --git a/src/plugin_tc.c b/src/plugin_tc.c index a300ea6a..0cd85ee8 100644 --- a/src/plugin_tc.c +++ b/src/plugin_tc.c @@ -376,7 +376,7 @@ static inline void tc_device_commit(struct tc_device *d) { if(unlikely(!d->st_bytes)) d->st_bytes = rrdset_create_localhost(RRD_TYPE_TC, d->id, d->name ? d->name : d->id , d->family ? d->family : d->id, RRD_TYPE_TC ".qos", "Class Usage" - , "kilobits/s", 7000, rrd_update_every + , "kilobits/s", 7000, localhost->rrd_update_every , d->enabled_all_classes_qdiscs ? RRDSET_TYPE_LINE : RRDSET_TYPE_STACKED); @@ -415,7 +415,7 @@ static inline void tc_device_commit(struct tc_device *d) { d->st_packets = rrdset_create_localhost(RRD_TYPE_TC, id, name, d->family ? d->family : d->id , RRD_TYPE_TC ".qos_packets", "Class Packets", "packets/s", 7010 - , rrd_update_every, d->enabled_all_classes_qdiscs ? RRDSET_TYPE_LINE + , localhost->rrd_update_every, d->enabled_all_classes_qdiscs ? RRDSET_TYPE_LINE : RRDSET_TYPE_STACKED); } else { @@ -458,7 +458,7 @@ static inline void tc_device_commit(struct tc_device *d) { d->st_dropped = rrdset_create_localhost(RRD_TYPE_TC, id, name, d->family ? d->family : d->id , RRD_TYPE_TC ".qos_dropped", "Class Dropped Packets", "packets/s" - , 7020, rrd_update_every + , 7020, localhost->rrd_update_every , d->enabled_all_classes_qdiscs ? RRDSET_TYPE_LINE : RRDSET_TYPE_STACKED); } @@ -502,7 +502,7 @@ static inline void tc_device_commit(struct tc_device *d) { d->st_tokens = rrdset_create_localhost(RRD_TYPE_TC, id, name, d->family ? d->family : d->id , RRD_TYPE_TC ".qos_tokens", "Class Tokens", "tokens", 7030 - , rrd_update_every, RRDSET_TYPE_LINE); + , localhost->rrd_update_every, RRDSET_TYPE_LINE); } else { rrdset_next(d->st_tokens); @@ -545,7 +545,7 @@ static inline void tc_device_commit(struct tc_device *d) { d->st_ctokens = rrdset_create_localhost(RRD_TYPE_TC, id, name, d->family ? d->family : d->id , RRD_TYPE_TC ".qos_ctokens", "Class cTokens", "ctokens", 7040 - , rrd_update_every, RRDSET_TYPE_LINE); + , localhost->rrd_update_every, RRDSET_TYPE_LINE); } else { debug(D_TC_LOOP, "TC: Updating _ctokens chart for device '%s'", d->name?d->name:d->id); @@ -807,7 +807,7 @@ void *tc_main(void *ptr) { struct tc_device *device = NULL; struct tc_class *class = NULL; - snprintfz(buffer, TC_LINE_MAX, "exec %s %d", tc_script, rrd_update_every); + snprintfz(buffer, TC_LINE_MAX, "exec %s %d", tc_script, localhost->rrd_update_every); debug(D_TC_LOOP, "executing '%s'", buffer); fp = mypopen(buffer, (pid_t *)&tc_child_pid); @@ -992,7 +992,7 @@ void *tc_main(void *ptr) { if(unlikely(!stcpu)) stcpu = rrdset_find_localhost("netdata.plugin_tc_cpu"); if(unlikely(!stcpu)) { stcpu = rrdset_create_localhost("netdata", "plugin_tc_cpu", NULL, "tc.helper", NULL - , "NetData TC CPU usage", "milliseconds/s", 135000, rrd_update_every + , "NetData TC CPU usage", "milliseconds/s", 135000, localhost->rrd_update_every , RRDSET_TYPE_STACKED); rrddim_add(stcpu, "user", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL); rrddim_add(stcpu, "system", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL); @@ -1007,7 +1007,7 @@ void *tc_main(void *ptr) { if(unlikely(!sttime)) { sttime = rrdset_create_localhost("netdata", "plugin_tc_time", NULL, "tc.helper", NULL , "NetData TC script execution", "milliseconds/run", 135001 - , rrd_update_every, RRDSET_TYPE_AREA); + , localhost->rrd_update_every, RRDSET_TYPE_AREA); rrddim_add(sttime, "run_time", "run time", 1, 1, RRD_ALGORITHM_ABSOLUTE); } else rrdset_next(sttime); @@ -1056,7 +1056,7 @@ void *tc_main(void *ptr) { goto cleanup; } - sleep((unsigned int) rrd_update_every); + sleep((unsigned int) localhost->rrd_update_every); } cleanup: diff --git a/src/plugins_d.c b/src/plugins_d.c index 69d52bb9..1c91d8fc 100644 --- a/src/plugins_d.c +++ b/src/plugins_d.c @@ -370,8 +370,8 @@ void *pluginsd_worker_thread(void *arg) { // second+ run usec = dt_usec(&now, &last) - susec; error("PLUGINSD: %s last loop took %llu usec (worked for %llu, sleeped for %llu).\n", cd->fullfilename, usec + susec, usec, susec); - if(unlikely(usec < (rrd_update_every * USEC_PER_SEC / 2ULL))) susec = (rrd_update_every * USEC_PER_SEC) - usec; - else susec = rrd_update_every * USEC_PER_SEC / 2ULL; + if(unlikely(usec < (localhost->rrd_update_every * USEC_PER_SEC / 2ULL))) susec = (localhost->rrd_update_every * USEC_PER_SEC) - usec; + else susec = localhost->rrd_update_every * USEC_PER_SEC / 2ULL; } error("PLUGINSD: %s sleeping for %llu. Will kill with SIGCONT pid %d to wake it up.\n", cd->fullfilename, susec, cd->pid); @@ -526,7 +526,7 @@ void *pluginsd_main(void *ptr) { snprintfz(cd->fullfilename, FILENAME_MAX, "%s/%s", netdata_configured_plugins_dir, cd->filename); cd->enabled = enabled; - cd->update_every = (int) config_get_number(cd->id, "update every", rrd_update_every); + cd->update_every = (int) config_get_number(cd->id, "update every", localhost->rrd_update_every); cd->started_t = now_realtime_sec(); char *def = ""; diff --git a/src/registry.c b/src/registry.c index 73221285..164c9179 100644 --- a/src/registry.c +++ b/src/registry.c @@ -326,7 +326,7 @@ void registry_statistics(void) { if(!sts) sts = rrdset_find_localhost("netdata.registry_sessions"); if(!sts) { sts = rrdset_create_localhost("netdata", "registry_sessions", NULL, "registry", NULL - , "NetData Registry Sessions", "session", 131000, rrd_update_every + , "NetData Registry Sessions", "session", 131000, localhost->rrd_update_every , RRDSET_TYPE_LINE); rrddim_add(sts, "sessions", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); @@ -341,7 +341,7 @@ void registry_statistics(void) { if(!stc) stc = rrdset_find_localhost("netdata.registry_entries"); if(!stc) { stc = rrdset_create_localhost("netdata", "registry_entries", NULL, "registry", NULL, "NetData Registry Entries" - , "entries", 131100, rrd_update_every, RRDSET_TYPE_LINE); + , "entries", 131100, localhost->rrd_update_every, RRDSET_TYPE_LINE); rrddim_add(stc, "persons", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rrddim_add(stc, "machines", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); @@ -363,7 +363,7 @@ void registry_statistics(void) { if(!stm) stm = rrdset_find_localhost("netdata.registry_mem"); if(!stm) { stm = rrdset_create_localhost("netdata", "registry_mem", NULL, "registry", NULL, "NetData Registry Memory", "KB" - , 131300, rrd_update_every, RRDSET_TYPE_STACKED); + , 131300, localhost->rrd_update_every, RRDSET_TYPE_STACKED); rrddim_add(stm, "persons", NULL, 1, 1024, RRD_ALGORITHM_ABSOLUTE); rrddim_add(stm, "machines", NULL, 1, 1024, RRD_ALGORITHM_ABSOLUTE); diff --git a/src/rrd.c b/src/rrd.c index 2fa50d37..5cc72fae 100644 --- a/src/rrd.c +++ b/src/rrd.c @@ -11,8 +11,8 @@ int rrd_delete_unupdated_dimensions = 0; */ -int rrd_update_every = UPDATE_EVERY; -int rrd_default_history_entries = RRD_DEFAULT_HISTORY_ENTRIES; +int default_localhost_rrd_update_every = UPDATE_EVERY; +int default_localhost_rrd_history_entries = RRD_DEFAULT_HISTORY_ENTRIES; RRD_MEMORY_MODE default_localhost_rrd_memory_mode = RRD_MEMORY_MODE_SAVE; diff --git a/src/rrd.h b/src/rrd.h index 5ef86838..cbf2260b 100644 --- a/src/rrd.h +++ b/src/rrd.h @@ -3,11 +3,12 @@ #define UPDATE_EVERY 1 #define UPDATE_EVERY_MAX 3600 -extern int rrd_update_every; #define RRD_DEFAULT_HISTORY_ENTRIES 3600 #define RRD_HISTORY_ENTRIES_MAX (86400*10) -extern int rrd_default_history_entries; + +extern int default_localhost_rrd_update_every; +extern int default_localhost_rrd_history_entries; #define RRD_ID_LENGTH_MAX 200 @@ -302,6 +303,9 @@ struct rrdhost { char machine_guid[GUID_LEN + 1]; // the unique ID of this host uint32_t hash_machine_guid; // the hash of the unique ID + int rrd_update_every; // the update frequency of the host + int rrd_history_entries; // the number of history entries for the host's charts + int health_enabled; // 1 when this host has health enabled RRD_MEMORY_MODE rrd_memory_mode; // the memory more for the charts of this host diff --git a/src/rrd2json.c b/src/rrd2json.c index b06fb4ae..40e5bea7 100644 --- a/src/rrd2json.c +++ b/src/rrd2json.c @@ -93,8 +93,8 @@ void rrd_stats_api_v1_charts(BUFFER *wb) , localhost->hostname , program_version , os_type - , rrd_update_every - , rrd_default_history_entries + , localhost->rrd_update_every + , localhost->rrd_history_entries ); pthread_rwlock_rdlock(&localhost->rrdset_root_rwlock); @@ -438,8 +438,8 @@ void rrd_stats_all_json(BUFFER *wb) "\t\"memory\": %lu\n" "}\n" , localhost->hostname - , rrd_update_every - , rrd_default_history_entries + , localhost->rrd_update_every + , localhost->rrd_history_entries , memory ); } diff --git a/src/rrdhost.c b/src/rrdhost.c index 2261ac97..e899f69d 100644 --- a/src/rrdhost.c +++ b/src/rrdhost.c @@ -54,8 +54,10 @@ RRDHOST *rrdhost_create(const char *hostname, const char *guid) { RRDHOST *host = callocz(1, sizeof(RRDHOST)); - host->rrd_memory_mode = default_localhost_rrd_memory_mode; - host->health_enabled = default_localhost_health_enabled; + host->rrd_update_every = default_localhost_rrd_update_every; + host->rrd_history_entries = default_localhost_rrd_history_entries; + host->rrd_memory_mode = default_localhost_rrd_memory_mode; + host->health_enabled = default_localhost_health_enabled; pthread_rwlock_init(&(host->rrdset_root_rwlock), NULL); diff --git a/src/rrdset.c b/src/rrdset.c index 0b238d11..95108813 100644 --- a/src/rrdset.c +++ b/src/rrdset.c @@ -234,7 +234,7 @@ RRDSET *rrdset_create(RRDHOST *host, const char *type, const char *id, const cha return st; } - long rentries = config_get_number(fullid, "history", rrd_default_history_entries); + long rentries = config_get_number(fullid, "history", host->rrd_history_entries); long entries = align_entries_to_pagesize(rentries); if(entries != rentries) entries = config_set_number(fullid, "history", entries); diff --git a/src/sys_fs_cgroup.c b/src/sys_fs_cgroup.c index 51c2e2b7..50a8e622 100644 --- a/src/sys_fs_cgroup.c +++ b/src/sys_fs_cgroup.c @@ -64,9 +64,9 @@ void read_cgroup_plugin_configuration() { user_hash = simple_hash("user"); system_hash = simple_hash("system"); - cgroup_update_every = (int)config_get_number("plugin:cgroups", "update every", rrd_update_every); - if(cgroup_update_every < rrd_update_every) - cgroup_update_every = rrd_update_every; + cgroup_update_every = (int)config_get_number("plugin:cgroups", "update every", localhost->rrd_update_every); + if(cgroup_update_every < localhost->rrd_update_every) + cgroup_update_every = localhost->rrd_update_every; cgroup_check_for_new_every = (int)config_get_number("plugin:cgroups", "check for new cgroups every", cgroup_check_for_new_every * cgroup_update_every); if(cgroup_check_for_new_every < cgroup_update_every) diff --git a/src/unit_test.c b/src/unit_test.c index b7ba4aff..dc660667 100644 --- a/src/unit_test.c +++ b/src/unit_test.c @@ -885,7 +885,7 @@ int run_test(struct test *test) fprintf(stderr, "\nRunning test '%s':\n%s\n", test->name, test->description); default_localhost_rrd_memory_mode = RRD_MEMORY_MODE_RAM; - rrd_update_every = test->update_every; + default_localhost_rrd_update_every = test->update_every; char name[101]; snprintfz(name, 100, "unittest-%s", test->name); @@ -1092,7 +1092,7 @@ int unit_test(long delay, long shift) //debug_flags = 0xffffffff; default_localhost_rrd_memory_mode = RRD_MEMORY_MODE_RAM; - rrd_update_every = 1; + default_localhost_rrd_update_every = 1; int do_abs = 1; int do_inc = 1; diff --git a/src/web_client.c b/src/web_client.c index e38d70b9..794dcc72 100644 --- a/src/web_client.c +++ b/src/web_client.c @@ -1532,7 +1532,7 @@ int web_client_api_old_data_request(struct web_client *w, char *url, int datasou debug(D_WEB_CLIENT, "%llu: Found RRD data with name '%s'.", w->id, tok); // how many entries does the client want? - int lines = rrd_default_history_entries; + int lines = (int)st->entries; int group_count = 1; time_t after = 0, before = 0; int group_method = GROUP_AVERAGE; @@ -1934,7 +1934,7 @@ static inline void web_client_send_http_header(struct web_client *w) { // set a proper expiration date, if not already set if(unlikely(!w->response.data->expires)) { if(w->response.data->options & WB_CONTENT_NO_CACHEABLE) - w->response.data->expires = w->tv_ready.tv_sec + rrd_update_every; + w->response.data->expires = w->tv_ready.tv_sec + localhost->rrd_update_every; else w->response.data->expires = w->tv_ready.tv_sec + 86400; } -- 2.39.2