X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=src%2Fglobal_statistics.c;h=8575061ac1fd31222a3100bec09bd78294b890b8;hb=25ab875c31533a003f6f6f38592361fc1c8e8f06;hp=f39a4cf25575c9ca600b0bc6cfa828b7b7a26416;hpb=4573404814de3da6605595bbe0a43837fa48d568;p=netdata.git diff --git a/src/global_statistics.c b/src/global_statistics.c index f39a4cf2..8575061a 100644 --- a/src/global_statistics.c +++ b/src/global_statistics.c @@ -10,14 +10,14 @@ volatile struct global_statistics global_statistics = { .compressed_content_size = 0 }; -pthread_mutex_t global_statistics_mutex = PTHREAD_MUTEX_INITIALIZER; +netdata_mutex_t global_statistics_mutex = NETDATA_MUTEX_INITIALIZER; inline void global_statistics_lock(void) { - pthread_mutex_lock(&global_statistics_mutex); + netdata_mutex_lock(&global_statistics_mutex); } inline void global_statistics_unlock(void) { - pthread_mutex_unlock(&global_statistics_mutex); + netdata_mutex_unlock(&global_statistics_mutex); } void finished_web_request_statistics(uint64_t dt, @@ -25,7 +25,7 @@ void finished_web_request_statistics(uint64_t dt, uint64_t bytes_sent, uint64_t content_size, uint64_t compressed_content_size) { -#ifndef NETDATA_NO_ATOMIC_INSTRUCTIONS +#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS) uint64_t old_web_usec_max = global_statistics.web_usec_max; while(dt > old_web_usec_max) __atomic_compare_exchange(&global_statistics.web_usec_max, &old_web_usec_max, &dt, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); @@ -57,7 +57,7 @@ void finished_web_request_statistics(uint64_t dt, } void web_client_connected(void) { -#ifndef NETDATA_NO_ATOMIC_INSTRUCTIONS +#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS) __atomic_fetch_add(&global_statistics.connected_clients, 1, __ATOMIC_SEQ_CST); #else if (web_server_mode == WEB_SERVER_MODE_MULTI_THREADED) @@ -71,7 +71,7 @@ void web_client_connected(void) { } void web_client_disconnected(void) { -#ifndef NETDATA_NO_ATOMIC_INSTRUCTIONS +#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS) __atomic_fetch_sub(&global_statistics.connected_clients, 1, __ATOMIC_SEQ_CST); #else if (web_server_mode == WEB_SERVER_MODE_MULTI_THREADED) @@ -86,7 +86,7 @@ void web_client_disconnected(void) { inline void global_statistics_copy(struct global_statistics *gs, uint8_t options) { -#ifndef NETDATA_NO_ATOMIC_INSTRUCTIONS +#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS) gs->connected_clients = __atomic_fetch_add(&global_statistics.connected_clients, 0, __ATOMIC_SEQ_CST); gs->web_requests = __atomic_fetch_add(&global_statistics.web_requests, 0, __ATOMIC_SEQ_CST); gs->web_usec = __atomic_fetch_add(&global_statistics.web_usec, 0, __ATOMIC_SEQ_CST); @@ -129,14 +129,22 @@ void global_statistics_charts(void) { getrusage(RUSAGE_THREAD, &thread); getrusage(RUSAGE_SELF, &me); - if (!stcpu_thread) stcpu_thread = rrdset_find("netdata.plugin_proc_cpu"); +#ifdef __FreeBSD__ + if (!stcpu_thread) stcpu_thread = rrdset_find_localhost("netdata.plugin_freebsd_cpu"); if (!stcpu_thread) { - stcpu_thread = rrdset_create("netdata", "plugin_proc_cpu", NULL, "proc.internal", NULL, - "NetData Proc Plugin CPU usage", "milliseconds/s", 132000, rrd_update_every, - RRDSET_TYPE_STACKED); + stcpu_thread = rrdset_create_localhost("netdata", "plugin_freebsd_cpu", NULL, "freebsd", NULL + , "NetData FreeBSD Plugin CPU usage", "milliseconds/s", 132000 + , localhost->rrd_update_every, RRDSET_TYPE_STACKED); +#else + if (!stcpu_thread) stcpu_thread = rrdset_find_localhost("netdata.plugin_proc_cpu"); + if (!stcpu_thread) { + stcpu_thread = rrdset_create_localhost("netdata", "plugin_proc_cpu", NULL, "proc", NULL + , "NetData Proc Plugin CPU usage", "milliseconds/s", 132000 + , localhost->rrd_update_every, RRDSET_TYPE_STACKED); +#endif - rrddim_add(stcpu_thread, "user", NULL, 1, 1000, RRDDIM_INCREMENTAL); - rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRDDIM_INCREMENTAL); + rrddim_add(stcpu_thread, "user", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL); + rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL); } else rrdset_next(stcpu_thread); rrddim_set(stcpu_thread, "user", thread.ru_utime.tv_sec * 1000000ULL + thread.ru_utime.tv_usec); @@ -145,13 +153,13 @@ void global_statistics_charts(void) { // ---------------------------------------------------------------- - if (!stcpu) stcpu = rrdset_find("netdata.server_cpu"); + if (!stcpu) stcpu = rrdset_find_localhost("netdata.server_cpu"); if (!stcpu) { - stcpu = rrdset_create("netdata", "server_cpu", NULL, "netdata", NULL, "NetData CPU usage", "milliseconds/s", - 130000, rrd_update_every, RRDSET_TYPE_STACKED); + stcpu = rrdset_create_localhost("netdata", "server_cpu", NULL, "netdata", NULL, "NetData CPU usage" + , "milliseconds/s", 130000, localhost->rrd_update_every, RRDSET_TYPE_STACKED); - rrddim_add(stcpu, "user", NULL, 1, 1000, RRDDIM_INCREMENTAL); - rrddim_add(stcpu, "system", NULL, 1, 1000, RRDDIM_INCREMENTAL); + rrddim_add(stcpu, "user", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL); + rrddim_add(stcpu, "system", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL); } else rrdset_next(stcpu); rrddim_set(stcpu, "user", me.ru_utime.tv_sec * 1000000ULL + me.ru_utime.tv_usec); @@ -160,12 +168,12 @@ void global_statistics_charts(void) { // ---------------------------------------------------------------- - if (!stclients) stclients = rrdset_find("netdata.clients"); + if (!stclients) stclients = rrdset_find_localhost("netdata.clients"); if (!stclients) { - stclients = rrdset_create("netdata", "clients", NULL, "netdata", NULL, "NetData Web Clients", - "connected clients", 130200, rrd_update_every, RRDSET_TYPE_LINE); + stclients = rrdset_create_localhost("netdata", "clients", NULL, "netdata", NULL, "NetData Web Clients" + , "connected clients", 130200, localhost->rrd_update_every, RRDSET_TYPE_LINE); - rrddim_add(stclients, "clients", NULL, 1, 1, RRDDIM_ABSOLUTE); + rrddim_add(stclients, "clients", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } else rrdset_next(stclients); rrddim_set(stclients, "clients", gs.connected_clients); @@ -173,12 +181,12 @@ void global_statistics_charts(void) { // ---------------------------------------------------------------- - if (!streqs) streqs = rrdset_find("netdata.requests"); + if (!streqs) streqs = rrdset_find_localhost("netdata.requests"); if (!streqs) { - streqs = rrdset_create("netdata", "requests", NULL, "netdata", NULL, "NetData Web Requests", "requests/s", - 130300, rrd_update_every, RRDSET_TYPE_LINE); + streqs = rrdset_create_localhost("netdata", "requests", NULL, "netdata", NULL, "NetData Web Requests" + , "requests/s", 130300, localhost->rrd_update_every, RRDSET_TYPE_LINE); - rrddim_add(streqs, "requests", NULL, 1, 1, RRDDIM_INCREMENTAL); + rrddim_add(streqs, "requests", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); } else rrdset_next(streqs); rrddim_set(streqs, "requests", (collected_number) gs.web_requests); @@ -186,13 +194,13 @@ void global_statistics_charts(void) { // ---------------------------------------------------------------- - if (!stbytes) stbytes = rrdset_find("netdata.net"); + if (!stbytes) stbytes = rrdset_find_localhost("netdata.net"); if (!stbytes) { - stbytes = rrdset_create("netdata", "net", NULL, "netdata", NULL, "NetData Network Traffic", "kilobits/s", - 130000, rrd_update_every, RRDSET_TYPE_AREA); + stbytes = rrdset_create_localhost("netdata", "net", NULL, "netdata", NULL, "NetData Network Traffic" + , "kilobits/s", 130000, localhost->rrd_update_every, RRDSET_TYPE_AREA); - rrddim_add(stbytes, "in", NULL, 8, 1024, RRDDIM_INCREMENTAL); - rrddim_add(stbytes, "out", NULL, -8, 1024, RRDDIM_INCREMENTAL); + rrddim_add(stbytes, "in", NULL, 8, 1024, RRD_ALGORITHM_INCREMENTAL); + rrddim_add(stbytes, "out", NULL, -8, 1024, RRD_ALGORITHM_INCREMENTAL); } else rrdset_next(stbytes); rrddim_set(stbytes, "in", (collected_number) gs.bytes_received); @@ -201,13 +209,14 @@ void global_statistics_charts(void) { // ---------------------------------------------------------------- - if (!stduration) stduration = rrdset_find("netdata.response_time"); + if (!stduration) stduration = rrdset_find_localhost("netdata.response_time"); if (!stduration) { - stduration = rrdset_create("netdata", "response_time", NULL, "netdata", NULL, "NetData API Response Time", - "ms/request", 130400, rrd_update_every, RRDSET_TYPE_LINE); + stduration = rrdset_create_localhost("netdata", "response_time", NULL, "netdata", NULL + , "NetData API Response Time", "ms/request", 130400, localhost->rrd_update_every + , RRDSET_TYPE_LINE); - rrddim_add(stduration, "average", NULL, 1, 1000, RRDDIM_ABSOLUTE); - rrddim_add(stduration, "max", NULL, 1, 1000, RRDDIM_ABSOLUTE); + rrddim_add(stduration, "average", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); + rrddim_add(stduration, "max", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); } else rrdset_next(stduration); uint64_t gweb_usec = gs.web_usec; @@ -232,13 +241,13 @@ void global_statistics_charts(void) { // ---------------------------------------------------------------- - if (!stcompression) stcompression = rrdset_find("netdata.compression_ratio"); + if (!stcompression) stcompression = rrdset_find_localhost("netdata.compression_ratio"); if (!stcompression) { - stcompression = rrdset_create("netdata", "compression_ratio", NULL, "netdata", NULL, - "NetData API Responses Compression Savings Ratio", "percentage", 130500, - rrd_update_every, RRDSET_TYPE_LINE); + stcompression = rrdset_create_localhost("netdata", "compression_ratio", NULL, "netdata", NULL + , "NetData API Responses Compression Savings Ratio", "percentage" + , 130500, localhost->rrd_update_every, RRDSET_TYPE_LINE); - rrddim_add(stcompression, "savings", NULL, 1, 1000, RRDDIM_ABSOLUTE); + rrddim_add(stcompression, "savings", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); } else rrdset_next(stcompression); // since we don't lock here to read the global statistics @@ -259,4 +268,4 @@ void global_statistics_charts(void) { rrddim_set(stcompression, "savings", compression_ratio); rrdset_done(stcompression); -} \ No newline at end of file +}