improved idlejitter plugin; now it calculates min, max and average
Costa Tsaousis (ktsaou) committed
Apr 21, 2017 at 22:56 UTC
61d08b1418b6c99a7adb4d0faa6e8f189ec0b173
5 files changed
+55
-33
src/clocks.h
+2
@@ -55,6 +55,8 @@ typedef usec_t heartbeat_t;
55
#define USEC_PER_SEC 1000000ULL
56
#define MSEC_PER_SEC 1000ULL
57
58
+#define USEC_PER_MS 1000ULL
59
+
60
#ifndef HAVE_CLOCK_GETTIME
61
/* Fallback function for POSIX.1-2001 clock_gettime() function.
62
*
src/plugin_idlejitter.c
+48
-20
@@ -13,40 +13,68 @@ void *cpuidlejitter_main(void *ptr) {
13
if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
14
error("Cannot set pthread cancel state to ENABLE.");
15
16
- int sleep_ms = (int) config_get_number("plugin:idlejitter", "loop time in ms", CPU_IDLEJITTER_SLEEP_TIME_MS);
17
- if(sleep_ms <= 0) {
16
+ usec_t sleep_ut = config_get_number("plugin:idlejitter", "loop time in ms", CPU_IDLEJITTER_SLEEP_TIME_MS) * USEC_PER_MS;
17
+ if(sleep_ut <= 0) {
18
config_set_number("plugin:idlejitter", "loop time in ms", CPU_IDLEJITTER_SLEEP_TIME_MS);
19
- sleep_ms = CPU_IDLEJITTER_SLEEP_TIME_MS;
20
- }
21
-
22
- RRDSET *st = rrdset_find_localhost("system.idlejitter");
23
- if(!st) {
24
- st = rrdset_create_localhost("system", "idlejitter", NULL, "processes", NULL, "CPU Idle Jitter"
25
- , "microseconds lost/s", 9999, localhost->rrd_update_every, RRDSET_TYPE_LINE);
26
- rrddim_add(st, "jitter", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
19
+ sleep_ut = CPU_IDLEJITTER_SLEEP_TIME_MS * USEC_PER_MS;
20
}
21
22
+ RRDSET *st = rrdset_create_localhost(
23
+ "system"
24
+ , "idlejitter"
25
+ , NULL
26
+ , "processes"
27
+ , NULL
28
+ , "CPU Idle Jitter"
29
+ , "microseconds lost/s"
30
+ , 9999
31
+ , localhost->rrd_update_every
32
+ , RRDSET_TYPE_AREA
33
+ );
34
+ RRDDIM *rd_min = rrddim_add(st, "min", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
35
+ RRDDIM *rd_max = rrddim_add(st, "max", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
36
+ RRDDIM *rd_avg = rrddim_add(st, "average", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
37
+
38
+ usec_t update_every_ut = localhost->rrd_update_every * USEC_PER_SEC;
39
struct timeval before, after;
40
unsigned long long counter;
41
for(counter = 0; 1 ;counter++) {
32
- usec_t usec = 0, susec = 0;
42
+ int iterations = 0;
43
+ usec_t error_total = 0,
44
+ error_min = 0,
45
+ error_max = 0,
46
+ elapsed = 0;
47
48
if(netdata_exit) break;
49
36
- while(susec < (localhost->rrd_update_every * USEC_PER_SEC)) {
37
-
50
+ while(elapsed < update_every_ut) {
51
now_monotonic_timeval(&before);
39
- sleep_usec(sleep_ms * 1000);
52
+ sleep_usec(sleep_ut);
53
now_monotonic_timeval(&after);
54
42
- // calculate the time it took for a full loop
43
- usec = dt_usec(&after, &before);
44
- susec += usec;
55
+ usec_t dt = dt_usec(&after, &before);
56
+ elapsed += dt;
57
+
58
+ usec_t error = dt - sleep_ut;
59
+ error_total += error;
60
+
61
+ if(unlikely(!iterations))
62
+ error_min = error;
63
+ else if(error < error_min)
64
+ error_min = error;
65
+
66
+ if(error > error_max)
67
+ error_max = error;
68
+
69
+ iterations++;
70
}
46
- usec -= (sleep_ms * 1000);
71
48
- if(counter) rrdset_next(st);
49
- rrddim_set(st, "jitter", usec);
72
+ if(netdata_exit) break;
73
+
74
+ if(likely(counter)) rrdset_next(st);
75
+ rrddim_set_by_pointer(st, rd_min, error_min);
76
+ rrddim_set_by_pointer(st, rd_max, error_max);
77
+ rrddim_set_by_pointer(st, rd_avg, error_total / iterations);
78
rrdset_done(st);
79
}
80
web/dashboard.js
+3
-10
@@ -2721,16 +2721,9 @@ var NETDATA = window.NETDATA || {};
2721
}
2722
else {
2723
c = c.split(' ');
2724
- var added = 0;
2725
-
2726
- while(added < 20) {
2727
- len = c.length;
2728
- while(len--) {
2729
- added++;
2730
- this.colors_available.unshift(c[len]);
2731
- // this.log('adding color: ' + c[len]);
2732
- }
2733
- }
2724
+ len = c.length;
2725
+ while(len--)
2726
+ this.colors_available.unshift(c[len]);
2727
}
2728
}
2729
web/dashboard_info.js
-1
@@ -426,7 +426,6 @@ netdataDashboard.context = {
426
},
427
428
'system.idlejitter': {
429
- colors: '#5555AA',
429
info: 'Idle jitter is calculated by netdata. A thread is spawned that requests to sleep for a few microseconds. When the system wakes it up, it measures how many microseconds have passed. The difference between the requested and the actual duration of the sleep, is the <b>idle jitter</b>. This number is useful in real-time environments, where CPU jitter can affect the quality of the service (like VoIP media gateways).'
430
},
431
web/index.html
+2
-2
@@ -2895,7 +2895,7 @@
2895
});
2896
2897
NETDATA.requiredJs.push({
2898
- url: NETDATA.serverDefault + 'dashboard_info.js?v20170325-1',
2898
+ url: NETDATA.serverDefault + 'dashboard_info.js?v20170421-1',
2899
async: false,
2900
isAlreadyLoaded: function() { return false; }
2901
});
@@ -3523,4 +3523,4 @@
3523
</div>
3524
</body>
3525
</html>
3526
-<script type="text/javascript" src="dashboard.js?v20170419-6"></script>
3526
+<script type="text/javascript" src="dashboard.js?v20170421-1"></script>