@cryptotaxi247 / netdata-1 / commits / 7ca4628ec

added more check charts

Costa Tsaousis (ktsaou) committed May 16, 2014 at 04:48 UTC 7ca4628ecc12e4850c8d3ab69840cb16597fc4b3
1 file changed +65 -34
netdata.c
+65 -34
@@ -6071,16 +6071,48 @@ void *cpuidlejitter_main(void *ptr)
6071 sleep_ms = CPU_IDLEJITTER_SLEEP_TIME_MS;
6072 }
6073
6074 - unsigned long long total_susec = 0, loop_usec = 0;
6074 struct timeval before, after;
6076 - struct timeval loop1, loop2;
6075
6078 - gettimeofday(&loop1, NULL);
6076 + while(1) {
6077 + unsigned long long usec = 0, susec = 0;
6078 +
6079 + while(susec < (update_every * 1000000ULL)) {
6080 +
6081 + gettimeofday(&before, NULL);
6082 + usleep(sleep_ms * 1000);
6083 + gettimeofday(&after, NULL);
6084 +
6085 + // calculate the time it took for a full loop
6086 + usec = usecdiff(&after, &before);
6087 + susec += usec;
6088 + }
6089 + usec -= (sleep_ms * 1000);
6090 +
6091 + RRD_STATS *st = rrd_stats_find("system.idlejitter");
6092 + if(!st) {
6093 + st = rrd_stats_create("system", "idlejitter", NULL, "cpu", "CPU Idle Jitter", "microseconds lost/s", 9999, update_every, CHART_TYPE_LINE);
6094 +
6095 + rrd_stats_dimension_add(st, "jitter", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
6096 + }
6097 + else rrd_stats_next_usec(st, susec);
6098 +
6099 + rrd_stats_dimension_set(st, "jitter", usec);
6100 + rrd_stats_done(st);
6101 + }
6102 +
6103 + return NULL;
6104 +}
6105 +
6106 +// ----------------------------------------------------------------------------
6107 +// netdata checks
6108
6080 - RRD_STATS *jitter, *check1, *check2, *check3;
6109 +void *checks_main(void *ptr)
6110 +{
6111 + if(ptr) { ; }
6112 + unsigned long long usec = 0, susec = update_every * 1000000ULL, loop_usec = 0, total_susec = 0;
6113 + struct timeval now, last, loop;
6114
6082 - jitter = rrd_stats_create("system", "idlejitter", NULL, "cpu", "CPU Idle Jitter", "microseconds lost/s", 9999, update_every, CHART_TYPE_LINE);
6083 - rrd_stats_dimension_add(jitter, "jitter", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
6115 + RRD_STATS *check1, *check2, *check3, *apps_cpu = NULL;
6116
6117 check1 = rrd_stats_create("netdata", "check1", NULL, "netdata", "Caller gives microseconds", "a million !", 99999, update_every, CHART_TYPE_LINE);
6118 rrd_stats_dimension_add(check1, "absolute", NULL, -1, 1, RRD_DIMENSION_ABSOLUTE);
@@ -6093,38 +6125,28 @@ void *cpuidlejitter_main(void *ptr)
6125 check3 = rrd_stats_create("netdata", "checkdt", NULL, "netdata", "Clock difference", "microseconds diff", 99999, update_every, CHART_TYPE_LINE);
6126 rrd_stats_dimension_add(check3, "caller", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
6127 rrd_stats_dimension_add(check3, "netdata", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
6128 + rrd_stats_dimension_add(check3, "apps.plugin", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
6129
6130 + gettimeofday(&last, NULL);
6131 while(1) {
6098 - unsigned long long usec = 0, susec = 0;
6099 -
6100 - while(susec < (update_every * 1000000ULL)) {
6101 -
6102 - gettimeofday(&before, NULL);
6103 - usleep(sleep_ms * 1000);
6104 - gettimeofday(&after, NULL);
6132 + usleep(susec);
6133
6106 - // calculate the time it took for a full loop
6107 - usec = usecdiff(&after, &before);
6108 - susec += usec;
6109 - }
6110 - usec -= (sleep_ms * 1000);
6134 + // find the time to sleep in order to wait exactly update_every seconds
6135 + gettimeofday(&now, NULL);
6136 + loop_usec = usecdiff(&now, &last);
6137 + usec = loop_usec - susec;
6138 + debug(D_PROCNETDEV_LOOP, "CHECK: last loop took %llu usec (worked for %llu, sleeped for %llu).", loop_usec, usec, susec);
6139 +
6140 + if(usec < (update_every * 1000000ULL / 2ULL)) susec = (update_every * 1000000ULL) - usec;
6141 + else susec = update_every * 1000000ULL / 2ULL;
6142
6143 // --------------------------------------------------------------------
6144 // Calculate loop time
6145
6115 - gettimeofday(&loop2, NULL);
6116 - loop_usec = usecdiff(&loop2, &loop1);
6117 - loop1.tv_sec = loop2.tv_sec;
6118 - loop1.tv_usec = loop2.tv_usec;
6146 + last.tv_sec = now.tv_sec;
6147 + last.tv_usec = now.tv_usec;
6148 total_susec += loop_usec;
6149
6121 - // --------------------------------------------------------------------
6122 - // idle jitter
6123 -
6124 - if(jitter->counter_done) rrd_stats_next_usec(jitter, susec);
6125 - rrd_stats_dimension_set(jitter, "jitter", loop_usec);
6126 - rrd_stats_done(jitter);
6127 -
6150 // --------------------------------------------------------------------
6151 // check chart 1
6152
@@ -6144,10 +6166,12 @@ void *cpuidlejitter_main(void *ptr)
6166 // --------------------------------------------------------------------
6167 // check chart 3
6168
6147 - if(check3->counter_done) rrd_stats_next_usec(check3, susec);
6148 - gettimeofday(&loop2, NULL);
6149 - rrd_stats_dimension_set(check3, "caller", (long long)usecdiff(&loop2, &check1->last_collected));
6150 - rrd_stats_dimension_set(check3, "netdata", (long long)usecdiff(&loop2, &check2->last_collected));
6169 + if(!apps_cpu) apps_cpu = rrd_stats_find("apps.cpu");
6170 + if(check3->counter_done) rrd_stats_next_usec(check3, loop_usec);
6171 + gettimeofday(&loop, NULL);
6172 + rrd_stats_dimension_set(check3, "caller", (long long)usecdiff(&loop, &check1->last_collected));
6173 + rrd_stats_dimension_set(check3, "netdata", (long long)usecdiff(&loop, &check2->last_collected));
6174 + if(apps_cpu) rrd_stats_dimension_set(check3, "apps.plugin", (long long)usecdiff(&loop, &apps_cpu->last_collected));
6175 rrd_stats_done(check3);
6176 }
6177
@@ -7013,7 +7037,7 @@ int main(int argc, char **argv)
7037 for (i = 1 ; i < 65 ;i++) if(i != SIGSEGV && i != SIGFPE) signal(i, sig_handler);
7038
7039
7016 - pthread_t p_proc, p_tc, p_jitter, p_pluginsd;
7040 + pthread_t p_proc, p_tc, p_jitter, p_pluginsd, p_checks;
7041
7042 // spawn childs to collect data
7043 if(config_get_boolean("plugins", "tc", 1)) {
@@ -7042,6 +7066,13 @@ int main(int argc, char **argv)
7066 else if(pthread_detach(p_pluginsd))
7067 error("Cannot request detach of newly created plugins.d thread.");
7068
7069 + if(config_get_boolean("plugins", "checks", 1)) {
7070 + if(pthread_create(&p_checks, NULL, checks_main, NULL))
7071 + error("failed to create new thread for checks.");
7072 + else if(pthread_detach(p_checks))
7073 + error("Cannot request detach of newly created checks thread.");
7074 + }
7075 +
7076 // the main process - the web server listener
7077 // this never ends
7078 socket_listen_main(NULL);