summaryrefslogtreecommitdiffstats
path: root/src/plugin_checks.c
diff options
context:
space:
mode:
authorLennart Weller <lhw@ring0.de>2017-01-24 15:21:16 +0000
committerLennart Weller <lhw@ring0.de>2017-01-24 15:21:16 +0000
commitef0c127e7f95d2db2715b9e99fe758eebc7dabd3 (patch)
treeea5d62342aba06f376f3be63aab898503b56f3ec /src/plugin_checks.c
parentupdate watch file and files-exclude (diff)
parentNew upstream version 1.5.0+dfsg (diff)
downloadnetdata-ef0c127e7f95d2db2715b9e99fe758eebc7dabd3.tar.xz
netdata-ef0c127e7f95d2db2715b9e99fe758eebc7dabd3.zip
Merge tag 'upstream/1.5.0+dfsg'
Upstream version 1.5.0+dfsg
Diffstat (limited to 'src/plugin_checks.c')
-rw-r--r--src/plugin_checks.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/plugin_checks.c b/src/plugin_checks.c
index 007d6565f..fcc542e68 100644
--- a/src/plugin_checks.c
+++ b/src/plugin_checks.c
@@ -1,8 +1,7 @@
#include "common.h"
-void *checks_main(void *ptr)
-{
- if(ptr) { ; }
+void *checks_main(void *ptr) {
+ struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
info("CHECKS thread created with task id %d", gettid());
@@ -12,7 +11,7 @@ void *checks_main(void *ptr)
if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
error("Cannot set pthread cancel state to ENABLE.");
- unsigned long long usec = 0, susec = rrd_update_every * 1000000ULL, loop_usec = 0, total_susec = 0;
+ usec_t usec = 0, susec = rrd_update_every * USEC_PER_SEC, loop_usec = 0, total_susec = 0;
struct timeval now, last, loop;
RRDSET *check1, *check2, *check3, *apps_cpu = NULL;
@@ -30,18 +29,18 @@ void *checks_main(void *ptr)
rrddim_add(check3, "netdata", NULL, 1, 1, RRDDIM_ABSOLUTE);
rrddim_add(check3, "apps.plugin", NULL, 1, 1, RRDDIM_ABSOLUTE);
- gettimeofday(&last, NULL);
+ now_realtime_timeval(&last);
while(1) {
usleep(susec);
// find the time to sleep in order to wait exactly update_every seconds
- gettimeofday(&now, NULL);
- loop_usec = usec_dt(&now, &last);
+ now_realtime_timeval(&now);
+ loop_usec = dt_usec(&now, &last);
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 * 1000000ULL / 2ULL)) susec = (rrd_update_every * 1000000ULL) - usec;
- else susec = rrd_update_every * 1000000ULL / 2ULL;
+ 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;
// --------------------------------------------------------------------
// Calculate loop time
@@ -71,13 +70,16 @@ void *checks_main(void *ptr)
if(!apps_cpu) apps_cpu = rrdset_find("apps.cpu");
if(check3->counter_done) rrdset_next_usec(check3, loop_usec);
- gettimeofday(&loop, NULL);
- rrddim_set(check3, "caller", (long long) usec_dt(&loop, &check1->last_collected_time));
- rrddim_set(check3, "netdata", (long long) usec_dt(&loop, &check2->last_collected_time));
- if(apps_cpu) rrddim_set(check3, "apps.plugin", (long long) usec_dt(&loop, &apps_cpu->last_collected_time));
+ now_realtime_timeval(&loop);
+ rrddim_set(check3, "caller", (long long) dt_usec(&loop, &check1->last_collected_time));
+ rrddim_set(check3, "netdata", (long long) dt_usec(&loop, &check2->last_collected_time));
+ if(apps_cpu) rrddim_set(check3, "apps.plugin", (long long) dt_usec(&loop, &apps_cpu->last_collected_time));
rrdset_done(check3);
}
+ info("CHECKS thread exiting");
+
+ static_thread->enabled = 0;
pthread_exit(NULL);
return NULL;
}