#include "global_statistics.h"
-struct global_statistics global_statistics = { 0ULL, 0ULL, 0ULL, 0ULL };
+struct global_statistics global_statistics = { 0, 0ULL, 0ULL, 0ULL, 0ULL};
pthread_mutex_t global_statistics_mutex = PTHREAD_MUTEX_INITIALIZER;
// global statistics
struct global_statistics {
- unsigned long long connected_clients;
- unsigned long long web_requests;
- unsigned long long bytes_received;
- unsigned long long bytes_sent;
-
+ unsigned long volatile connected_clients;
+ unsigned long long volatile web_requests;
+ unsigned long long volatile web_usec;
+ unsigned long long volatile bytes_received;
+ unsigned long long volatile bytes_sent;
};
extern struct global_statistics global_statistics;
void *proc_main(void *ptr)
{
- if(ptr) { ; }
+ static unsigned long long old_web_requests = 0, old_web_usec = 0;
+ (void)ptr;
info("PROC Plugin thread created with task id %d", gettid());
unsigned long long sunext = (time(NULL) - (time(NULL) % rrd_update_every) + rrd_update_every) * 1000000ULL;
unsigned long long sunow;
- RRDSET *stcpu = NULL, *stcpu_thread = NULL, *stclients = NULL, *streqs = NULL, *stbytes = NULL;
+ RRDSET *stcpu = NULL, *stcpu_thread = NULL, *stclients = NULL, *streqs = NULL, *stbytes = NULL, *stduration = NULL;
for(;1;) {
if(unlikely(netdata_exit)) break;
// ----------------------------------------------------------------
+ if(!stduration) stduration = rrdset_find("netdata.response_time");
+ if(!stduration) {
+ stduration = rrdset_create("netdata", "response_time", NULL, "netdata", NULL, "NetData Average API Response Time", "ms/request", 130400, rrd_update_every, RRDSET_TYPE_LINE);
+
+ rrddim_add(stduration, "response_time", "response time", 1, 1000, RRDDIM_ABSOLUTE);
+ }
+ else rrdset_next(stduration);
+
+ unsigned long long gweb_usec = global_statistics.web_usec;
+ unsigned long long gweb_requests = global_statistics.web_requests;
+
+ unsigned long long web_usec = gweb_usec - old_web_usec;
+ unsigned long long web_requests = gweb_requests - old_web_requests;
+
+ old_web_usec = gweb_usec;
+ old_web_requests = gweb_requests;
+
+ if(!web_requests) web_requests = 1;
+
+ rrddim_set(stduration, "response_time", web_usec / web_requests);
+ rrdset_done(stduration);
+
+ // ----------------------------------------------------------------
+
registry_statistics();
}
}
struct timeval tv;
gettimeofday(&tv, NULL);
+ debug(D_WEB_CLIENT, "%llu: Reseting client.", w->id);
+
+ if(w->stats_received_bytes || w->stats_sent_bytes) {
+ global_statistics_lock();
+ global_statistics.web_requests++;
+ global_statistics.web_usec += usecdiff(&tv, &w->tv_in);
+ global_statistics.bytes_received += w->stats_received_bytes;
+ global_statistics.bytes_sent += w->stats_sent_bytes;
+ global_statistics_unlock();
+ }
+ w->stats_received_bytes = 0;
+ w->stats_sent_bytes = 0;
+
long sent = (w->mode == WEB_CLIENT_MODE_FILECOPY)?w->response.rlen:w->response.data->len;
#ifdef NETDATA_WITH_ZLIB
w->last_url
);
- debug(D_WEB_CLIENT, "%llu: Reseting client.", w->id);
-
if(unlikely(w->mode == WEB_CLIENT_MODE_FILECOPY)) {
debug(D_WEB_CLIENT, "%llu: Closing filecopy input file.", w->id);
close(w->ifd);
else { // what_to_do == 0
gettimeofday(&w->tv_in, NULL);
- global_statistics_lock();
- global_statistics.web_requests++;
- global_statistics_unlock();
-
// copy the URL - we are going to overwrite parts of it
// FIXME -- we should avoid it
strncpyz(w->last_url, w->decoded_url, URL_MAX);
, w->id
, buffer_strlen(w->response.header_output)
, bytes);
- else {
- global_statistics_lock();
- global_statistics.bytes_sent += bytes;
- global_statistics_unlock();
- }
+ else
+ w->stats_sent_bytes += bytes;
// enable TCP_NODELAY, to send all data immediately at the next send()
flag = 1;
errno = 0;
break;
}
-
- global_statistics_lock();
- global_statistics.bytes_sent += bytes;
- global_statistics_unlock();
+ else
+ w->stats_sent_bytes += bytes;
}
if(w->wait_receive && FD_ISSET(w->ifd, &ifds)) {
errno = 0;
break;
}
+ else
+ w->stats_received_bytes += bytes;
if(w->mode == WEB_CLIENT_MODE_NORMAL) {
debug(D_WEB_CLIENT, "%llu: Attempting to process received data (%ld bytes).", w->id, bytes);
web_client_process(w);
}
- global_statistics_lock();
- global_statistics.bytes_received += bytes;
- global_statistics_unlock();
}
}
int wait_receive;
int wait_send;
+ unsigned long stats_received_bytes;
+ unsigned long stats_sent_bytes;
+
struct web_client *prev;
struct web_client *next;
};