diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-05-19 12:33:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-05-19 12:33:27 +0000 |
commit | 841395dd16f470e3c051a0a4fff5b91efc983c30 (patch) | |
tree | 4115f6eedcddda75067130b80acaff9e51612f49 /daemon/global_statistics.c | |
parent | Adding upstream version 1.30.1. (diff) | |
download | netdata-841395dd16f470e3c051a0a4fff5b91efc983c30.tar.xz netdata-841395dd16f470e3c051a0a4fff5b91efc983c30.zip |
Adding upstream version 1.31.0.upstream/1.31.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | daemon/global_statistics.c | 155 |
1 files changed, 86 insertions, 69 deletions
diff --git a/daemon/global_statistics.c b/daemon/global_statistics.c index 7e7835513..edd261476 100644 --- a/daemon/global_statistics.c +++ b/daemon/global_statistics.c @@ -4,6 +4,7 @@ #define GLOBAL_STATS_RESET_WEB_USEC_MAX 0x01 +#define CONFIG_SECTION_GLOBAL_STATISTICS "global statistics" static struct global_statistics { volatile uint16_t connected_clients; @@ -180,63 +181,17 @@ void global_statistics_charts(void) { static collected_number compression_ratio = -1, average_response_time = -1; + static time_t netdata_start_time = 0; + if (!netdata_start_time) + netdata_start_time = now_boottime_sec(); + time_t netdata_uptime = now_boottime_sec() - netdata_start_time; + struct global_statistics gs; - struct rusage me, thread; + struct rusage me; global_statistics_copy(&gs, GLOBAL_STATS_RESET_WEB_USEC_MAX); - getrusage(RUSAGE_THREAD, &thread); getrusage(RUSAGE_SELF, &me); - { - static RRDSET *st_cpu_thread = NULL; - static RRDDIM *rd_cpu_thread_user = NULL, - *rd_cpu_thread_system = NULL; - -#ifdef __FreeBSD__ - if (unlikely(!st_cpu_thread)) { - st_cpu_thread = rrdset_create_localhost( - "netdata" - , "plugin_freebsd_cpu" - , NULL - , "freebsd" - , NULL - , "NetData FreeBSD Plugin CPU usage" - , "milliseconds/s" - , "netdata" - , "stats" - , 132000 - , localhost->rrd_update_every - , RRDSET_TYPE_STACKED - ); -#else - if (unlikely(!st_cpu_thread)) { - st_cpu_thread = rrdset_create_localhost( - "netdata" - , "plugin_proc_cpu" - , NULL - , "proc" - , NULL - , "NetData Proc Plugin CPU usage" - , "milliseconds/s" - , "netdata" - , "stats" - , 132000 - , localhost->rrd_update_every - , RRDSET_TYPE_STACKED - ); -#endif - - rd_cpu_thread_user = rrddim_add(st_cpu_thread, "user", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL); - rd_cpu_thread_system = rrddim_add(st_cpu_thread, "system", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL); - } - else - rrdset_next(st_cpu_thread); - - rrddim_set_by_pointer(st_cpu_thread, rd_cpu_thread_user, thread.ru_utime.tv_sec * 1000000ULL + thread.ru_utime.tv_usec); - rrddim_set_by_pointer(st_cpu_thread, rd_cpu_thread_system, thread.ru_stime.tv_sec * 1000000ULL + thread.ru_stime.tv_usec); - rrdset_done(st_cpu_thread); - } - // ---------------------------------------------------------------- { @@ -251,7 +206,7 @@ void global_statistics_charts(void) { , NULL , "netdata" , NULL - , "NetData CPU usage" + , "Netdata CPU usage" , "milliseconds/s" , "netdata" , "stats" @@ -274,6 +229,35 @@ void global_statistics_charts(void) { // ---------------------------------------------------------------- { + static RRDSET *st_uptime = NULL; + static RRDDIM *rd_uptime = NULL; + + if (unlikely(!st_uptime)) { + st_uptime = rrdset_create_localhost( + "netdata", + "uptime", + NULL, + "netdata", + NULL, + "Netdata uptime", + "seconds", + "netdata", + "stats", + 130100, + localhost->rrd_update_every, + RRDSET_TYPE_LINE); + + rd_uptime = rrddim_add(st_uptime, "uptime", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); + } else + rrdset_next(st_uptime); + + rrddim_set_by_pointer(st_uptime, rd_uptime, netdata_uptime); + rrdset_done(st_uptime); + } + + // ---------------------------------------------------------------- + + { static RRDSET *st_clients = NULL; static RRDDIM *rd_clients = NULL; @@ -284,7 +268,7 @@ void global_statistics_charts(void) { , NULL , "netdata" , NULL - , "NetData Web Clients" + , "Netdata Web Clients" , "connected clients" , "netdata" , "stats" @@ -315,7 +299,7 @@ void global_statistics_charts(void) { , NULL , "netdata" , NULL - , "NetData Web Requests" + , "Netdata Web Requests" , "requests/s" , "netdata" , "stats" @@ -347,7 +331,7 @@ void global_statistics_charts(void) { , NULL , "netdata" , NULL - , "NetData Network Traffic" + , "Netdata Network Traffic" , "kilobits/s" , "netdata" , "stats" @@ -381,7 +365,7 @@ void global_statistics_charts(void) { , NULL , "netdata" , NULL - , "NetData API Response Time" + , "Netdata API Response Time" , "milliseconds/request" , "netdata" , "stats" @@ -430,7 +414,7 @@ void global_statistics_charts(void) { , NULL , "netdata" , NULL - , "NetData API Responses Compression Savings Ratio" + , "Netdata API Responses Compression Savings Ratio" , "percentage" , "netdata" , "stats" @@ -477,7 +461,7 @@ void global_statistics_charts(void) { , NULL , "queries" , NULL - , "NetData API Queries" + , "Netdata API Queries" , "queries/s" , "netdata" , "stats" @@ -510,7 +494,7 @@ void global_statistics_charts(void) { , NULL , "queries" , NULL - , "NetData API Points" + , "Netdata API Points" , "points/s" , "netdata" , "stats" @@ -579,7 +563,7 @@ void global_statistics_charts(void) { , NULL , "dbengine" , NULL - , "NetData DB engine data extents' compression savings ratio" + , "Netdata DB engine data extents' compression savings ratio" , "percentage" , "netdata" , "stats" @@ -621,7 +605,7 @@ void global_statistics_charts(void) { , NULL , "dbengine" , NULL - , "NetData DB engine page cache hit ratio" + , "Netdata DB engine page cache hit ratio" , "percentage" , "netdata" , "stats" @@ -676,7 +660,7 @@ void global_statistics_charts(void) { , NULL , "dbengine" , NULL - , "NetData dbengine page cache statistics" + , "Netdata dbengine page cache statistics" , "pages" , "netdata" , "stats" @@ -721,7 +705,7 @@ void global_statistics_charts(void) { , NULL , "dbengine" , NULL - , "NetData dbengine long-term page statistics" + , "Netdata dbengine long-term page statistics" , "pages" , "netdata" , "stats" @@ -761,7 +745,7 @@ void global_statistics_charts(void) { , NULL , "dbengine" , NULL - , "NetData DB engine I/O throughput" + , "Netdata DB engine I/O throughput" , "MiB/s" , "netdata" , "stats" @@ -795,7 +779,7 @@ void global_statistics_charts(void) { , NULL , "dbengine" , NULL - , "NetData DB engine I/O operations" + , "Netdata DB engine I/O operations" , "operations/s" , "netdata" , "stats" @@ -830,7 +814,7 @@ void global_statistics_charts(void) { , NULL , "dbengine" , NULL - , "NetData DB engine errors" + , "Netdata DB engine errors" , "errors/s" , "netdata" , "stats" @@ -867,7 +851,7 @@ void global_statistics_charts(void) { , NULL , "dbengine" , NULL - , "NetData DB engine File Descriptors" + , "Netdata DB engine File Descriptors" , "descriptors" , "netdata" , "stats" @@ -906,7 +890,7 @@ void global_statistics_charts(void) { , NULL , "dbengine" , NULL - , "NetData DB engine RAM usage" + , "Netdata DB engine RAM usage" , "MiB" , "netdata" , "stats" @@ -948,3 +932,36 @@ void global_statistics_charts(void) { #endif } + +static void global_statistics_cleanup(void *ptr) +{ + struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr; + static_thread->enabled = NETDATA_MAIN_THREAD_EXITING; + + info("cleaning up..."); + + static_thread->enabled = NETDATA_MAIN_THREAD_EXITED; +} + +void *global_statistics_main(void *ptr) +{ + netdata_thread_cleanup_push(global_statistics_cleanup, ptr); + + int update_every = + (int)config_get_number("CONFIG_SECTION_GLOBAL_STATISTICS", "update every", localhost->rrd_update_every); + if (update_every < localhost->rrd_update_every) + update_every = localhost->rrd_update_every; + + usec_t step = update_every * USEC_PER_SEC; + heartbeat_t hb; + heartbeat_init(&hb); + while (!netdata_exit) { + heartbeat_next(&hb, step); + + global_statistics_charts(); + registry_statistics(); + } + + netdata_thread_cleanup_pop(1); + return NULL; +} |