]> arthur.barton.de Git - netdata.git/blob - src/plugin_tc.c
Merge branch 'master' of github.com:firehol/netdata
[netdata.git] / src / plugin_tc.c
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <sys/types.h>
8 #include <sys/resource.h>
9
10 #include "avl.h"
11 #include "log.h"
12 #include "common.h"
13 #include "appconfig.h"
14 #include "rrd.h"
15 #include "popen.h"
16 #include "plugin_tc.h"
17
18 #define RRD_TYPE_TC                                     "tc"
19 #define RRD_TYPE_TC_LEN                         strlen(RRD_TYPE_TC)
20
21 // ----------------------------------------------------------------------------
22 // /sbin/tc processor
23 // this requires the script plugins.d/tc-qos-helper.sh
24
25 #define TC_LINE_MAX 1024
26
27 struct tc_class {
28         avl avl;
29
30         char *id;
31         uint32_t hash;
32
33         char *name;
34
35         char *leafid;
36         uint32_t leaf_hash;
37
38         char *parentid;
39         uint32_t parent_hash;
40
41         char hasparent;
42         char isleaf;
43         unsigned long long bytes;
44
45         char updated;   // updated bytes
46         char seen;              // seen in the tc list (even without bytes)
47
48         struct tc_class *next;
49         struct tc_class *prev;
50 };
51
52 struct tc_device {
53         avl avl;
54
55         char *id;
56         uint32_t hash;
57
58         char *name;
59         char *family;
60
61         avl_tree classes_index;
62
63         struct tc_class *classes;
64 };
65
66
67 // ----------------------------------------------------------------------------
68 // tc_device index
69
70 static int tc_device_iterator(avl *a) { if(a) {}; return 0; }
71
72 static int tc_device_compare(void* a, void* b) {
73         if(((struct tc_device *)a)->hash < ((struct tc_device *)b)->hash) return -1;
74         else if(((struct tc_device *)a)->hash > ((struct tc_device *)b)->hash) return 1;
75         else return strcmp(((struct tc_device *)a)->id, ((struct tc_device *)b)->id);
76 }
77
78 avl_tree tc_device_root_index = {
79                 NULL,
80                 tc_device_compare
81 };
82
83 #define tc_device_index_add(st) avl_insert(&tc_device_root_index, (avl *)(st))
84 #define tc_device_index_del(st) avl_remove(&tc_device_root_index, (avl *)(st))
85
86 static struct tc_device *tc_device_index_find(const char *id, uint32_t hash) {
87         struct tc_device *result = NULL, tmp;
88         tmp.id = (char *)id;
89         tmp.hash = (hash)?hash:simple_hash(tmp.id);
90
91         avl_search(&(tc_device_root_index), (avl *)&tmp, tc_device_iterator, (avl **)&result);
92         return result;
93 }
94
95
96 // ----------------------------------------------------------------------------
97 // tc_class index
98
99 static int tc_class_iterator(avl *a) { if(a) {}; return 0; }
100
101 static int tc_class_compare(void* a, void* b) {
102         if(((struct tc_class *)a)->hash < ((struct tc_class *)b)->hash) return -1;
103         else if(((struct tc_class *)a)->hash > ((struct tc_class *)b)->hash) return 1;
104         else return strcmp(((struct tc_class *)a)->id, ((struct tc_class *)b)->id);
105 }
106
107 #define tc_class_index_add(st, rd) avl_insert(&((st)->classes_index), (avl *)(rd))
108 #define tc_class_index_del(st, rd) avl_remove(&((st)->classes_index), (avl *)(rd))
109
110 static struct tc_class *tc_class_index_find(struct tc_device *st, const char *id, uint32_t hash) {
111         struct tc_class *result = NULL, tmp;
112         tmp.id = (char *)id;
113         tmp.hash = (hash)?hash:simple_hash(tmp.id);
114
115         avl_search(&(st->classes_index), (avl *)&tmp, tc_class_iterator, (avl **)&result);
116         return result;
117 }
118
119 // ----------------------------------------------------------------------------
120
121 static void tc_class_free(struct tc_device *n, struct tc_class *c) {
122         debug(D_TC_LOOP, "Removing from device '%s' class '%s', parentid '%s', leafid '%s', seen=%d", n->id, c->id, c->parentid?c->parentid:"", c->leafid?c->leafid:"", c->seen);
123
124         if(c->next) c->next->prev = c->prev;
125         if(c->prev) c->prev->next = c->next;
126         if(n->classes == c) n->classes = c->next;
127
128         tc_class_index_del(n, c);
129
130         if(c->id) free(c->id);
131         if(c->name) free(c->name);
132         if(c->leafid) free(c->leafid);
133         if(c->parentid) free(c->parentid);
134
135         free(c);
136 }
137
138 static void tc_device_classes_cleanup(struct tc_device *d) {
139         static int cleanup_every = 999;
140
141         if(cleanup_every > 0) {
142                 cleanup_every = -config_get_number("plugin:tc", "cleanup unused classes every", 60);
143                 if(cleanup_every > 0) cleanup_every = -cleanup_every;
144                 if(cleanup_every == 0) cleanup_every = -1;
145         }
146
147         struct tc_class *c = d->classes;
148         while(c) {
149                 if(c->seen < cleanup_every) {
150                         struct tc_class *nc = c->next;
151                         tc_class_free(d, c);
152                         c = nc;
153                 }
154                 else c = c->next;
155
156                 if(c) {
157                         c->updated = 0;
158                         c->seen--;
159                 }
160         }
161 }
162
163 static void tc_device_commit(struct tc_device *d)
164 {
165         static int enable_new_interfaces = -1;
166
167         if(enable_new_interfaces == -1) enable_new_interfaces = config_get_boolean("plugin:tc", "enable new interfaces detected at runtime", 1);
168         
169         // we only need to add leaf classes
170         struct tc_class *c, *x;
171
172         // set all classes
173         for(c = d->classes ; c ; c = c->next) {
174                 c->isleaf = 1;
175                 c->hasparent = 0;
176         }
177
178         // mark the classes as leafs and parents
179         for(c = d->classes ; c ; c = c->next) {
180                 if(!c->updated) continue;
181
182                 for(x = d->classes ; x ; x = x->next) {
183                         if(!x->updated) continue;
184
185                         if(c == x) continue;
186
187                         if(x->parentid && (
188                                 (               c->hash      == x->parent_hash && strcmp(c->id,     x->parentid) == 0) ||
189                                 (c->leafid   && c->leaf_hash == x->parent_hash && strcmp(c->leafid, x->parentid) == 0))) {
190                                 // debug(D_TC_LOOP, "TC: In device '%s', class '%s' (leafid: '%s') has as leaf class '%s' (parentid: '%s').", d->name?d->name:d->id, c->name?c->name:c->id, c->leafid?c->leafid:c->id, x->name?x->name:x->id, x->parentid?x->parentid:x->id);
191                                 c->isleaf = 0;
192                                 x->hasparent = 1;
193                         }
194                 }
195         }
196         
197         // debugging:
198         /*
199         for ( c = d->classes ; c ; c = c->next) {
200                 if(c->isleaf && c->hasparent) debug(D_TC_LOOP, "TC: Device %s, class %s, OK", d->name, c->id);
201                 else debug(D_TC_LOOP, "TC: Device %s, class %s, IGNORE (isleaf: %d, hasparent: %d, parent: %s)", d->name, c->id, c->isleaf, c->hasparent, c->parentid);
202         }
203         */
204
205         // we need at least a class
206         for(c = d->classes ; c ; c = c->next) {
207                 // debug(D_TC_LOOP, "TC: Device '%s', class '%s', isLeaf=%d, HasParent=%d, Seen=%d", d->name?d->name:d->id, c->name?c->name:c->id, c->isleaf, c->hasparent, c->seen);
208                 if(!c->updated) continue;
209                 if(c->isleaf && c->hasparent) break;
210         }
211         if(!c) {
212                 debug(D_TC_LOOP, "TC: Ignoring TC device '%s'. No leaf classes.", d->name?d->name:d->id);
213                 tc_device_classes_cleanup(d);
214                 return;
215         }
216
217         char var_name[CONFIG_MAX_NAME + 1];
218         snprintf(var_name, CONFIG_MAX_NAME, "qos for %s", d->id);
219         if(config_get_boolean("plugin:tc", var_name, enable_new_interfaces)) {
220                 RRDSET *st = rrdset_find_bytype(RRD_TYPE_TC, d->id);
221                 if(!st) {
222                         debug(D_TC_LOOP, "TC: Creating new chart for device '%s'", d->name?d->name:d->id);
223
224                         st = rrdset_create(RRD_TYPE_TC, d->id, d->name?d->name:d->id, d->family?d->family:d->id, "Class Usage", "kilobits/s", 1000, rrd_update_every, RRDSET_TYPE_STACKED);
225
226                         for(c = d->classes ; c ; c = c->next) {
227                                 if(!c->updated) continue;
228
229                                 if(c->isleaf && c->hasparent)
230                                         rrddim_add(st, c->id, c->name?c->name:c->id, 8, 1024 * rrd_update_every, RRDDIM_INCREMENTAL);
231                         }
232                 }
233                 else {
234                         debug(D_TC_LOOP, "TC: Updating chart for device '%s'", d->name?d->name:d->id);
235                         rrdset_next_plugins(st);
236
237                         if(d->name && strcmp(d->id, d->name) != 0) rrdset_set_name(st, d->name);
238                 }
239
240                 for(c = d->classes ; c ; c = c->next) {
241                         if(!c->updated) continue;
242
243                         if(c->isleaf && c->hasparent) {
244                                 RRDDIM *rd = rrddim_find(st, c->id);
245
246                                 if(!rd) {
247                                         debug(D_TC_LOOP, "TC: Adding to chart '%s', dimension '%s'", st->id, c->id, c->name);
248                                         
249                                         // new class, we have to add it
250                                         rd = rrddim_add(st, c->id, c->name?c->name:c->id, 8, 1024 * rrd_update_every, RRDDIM_INCREMENTAL);
251                                 }
252                                 else debug(D_TC_LOOP, "TC: Updating chart '%s', dimension '%s'", st->id, c->id);
253
254                                 rrddim_set_by_pointer(st, rd, c->bytes);
255
256                                 // if it has a name, different to the id
257                                 if(c->name) {
258                                         // update the rrd dimension with the new name
259                                         debug(D_TC_LOOP, "TC: Setting chart '%s', dimension '%s' name to '%s'", st->id, rd->id, c->name);
260                                         rrddim_set_name(st, rd, c->name);
261
262                                         free(c->name);
263                                         c->name = NULL;
264                                 }
265                         }
266                 }
267                 rrdset_done(st);
268         }
269
270         tc_device_classes_cleanup(d);
271 }
272
273 static void tc_device_set_class_name(struct tc_device *d, char *id, char *name)
274 {
275         struct tc_class *c = tc_class_index_find(d, id, 0);
276         if(c) {
277                 if(c->name) free(c->name);
278                 c->name = NULL;
279
280                 if(name && *name && strcmp(c->id, name) != 0) {
281                         debug(D_TC_LOOP, "TC: Setting device '%s', class '%s' name to '%s'", d->id, id, name);
282                         c->name = strdup(name);
283                 }
284         }
285 }
286
287 static void tc_device_set_device_name(struct tc_device *d, char *name) {
288         if(d->name) free(d->name);
289         d->name = NULL;
290
291         if(name && *name && strcmp(d->id, name) != 0) {
292                 debug(D_TC_LOOP, "TC: Setting device '%s' name to '%s'", d->id, name);
293                 d->name = strdup(name);
294         }
295 }
296
297 static void tc_device_set_device_family(struct tc_device *d, char *family) {
298         if(d->family) free(d->family);
299         d->family = NULL;
300
301         if(family && *family && strcmp(d->id, family) != 0) {
302                 debug(D_TC_LOOP, "TC: Setting device '%s' family to '%s'", d->id, family);
303                 d->family = strdup(family);
304         }
305         // no need for null termination - it is already null
306 }
307
308 static struct tc_device *tc_device_create(char *id)
309 {
310         struct tc_device *d = tc_device_index_find(id, 0);
311
312         if(!d) {
313                 debug(D_TC_LOOP, "TC: Creating device '%s'", id);
314
315                 d = calloc(1, sizeof(struct tc_device));
316                 if(!d) {
317                         fatal("Cannot allocate memory for tc_device %s", id);
318                         return NULL;
319                 }
320
321                 d->id = strdup(id);
322                 d->hash = simple_hash(d->id);
323
324                 d->classes_index.root = NULL;
325                 d->classes_index.compar = tc_class_compare;
326
327                 tc_device_index_add(d);
328         }
329
330         return(d);
331 }
332
333 static struct tc_class *tc_class_add(struct tc_device *n, char *id, char *parentid, char *leafid)
334 {
335         struct tc_class *c = tc_class_index_find(n, id, 0);
336
337         if(!c) {
338                 debug(D_TC_LOOP, "TC: Creating in device '%s', class id '%s', parentid '%s', leafid '%s'", n->id, id, parentid?parentid:"", leafid?leafid:"");
339
340                 c = calloc(1, sizeof(struct tc_class));
341                 if(!c) {
342                         fatal("Cannot allocate memory for tc class");
343                         return NULL;
344                 }
345
346                 if(n->classes) n->classes->prev = c;
347                 c->next = n->classes;
348                 n->classes = c;
349
350                 c->id = strdup(id);
351                 if(!c->id) {
352                         free(c);
353                         return NULL;
354                 }
355                 c->hash = simple_hash(c->id);
356
357                 if(parentid && *parentid) {
358                         c->parentid = strdup(parentid);
359                         c->parent_hash = simple_hash(c->parentid);
360                 }
361
362                 if(leafid && *leafid) {
363                         c->leafid = strdup(leafid);
364                         c->leaf_hash = simple_hash(c->leafid);
365                 }
366
367                 tc_class_index_add(n, c);
368         }
369
370         c->seen = 1;
371
372         return(c);
373 }
374 /*
375 static void tc_device_free(struct tc_device *n)
376 {
377         tc_device_index_del(n);
378
379         while(n->classes) tc_class_free(n, n->classes);
380
381         if(n->id) free(n->id);
382         if(n->name) free(n->name);
383         if(n->family) free(n->family);
384
385         free(n);
386 }
387 */
388
389 #define MAX_WORDS 20
390
391 static inline int tc_space(char c) {
392         switch(c) {
393         case ' ':
394         case '\t':
395         case '\r':
396         case '\n':
397                 return 1;
398
399         default:
400                 return 0;
401         }
402 }
403
404 static void tc_split_words(char *str, char **words, int max_words) {
405         char *s = str;
406         int i = 0;
407
408         // skip all white space
409         while(tc_space(*s)) s++;
410
411         // store the first word
412         words[i++] = s;
413
414         // while we have something
415         while(*s) {
416                 // if it is a space
417                 if(tc_space(*s)) {
418
419                         // terminate the word
420                         *s++ = '\0';
421
422                         // skip all white space
423                         while(tc_space(*s)) s++;
424
425                         // if we reached the end, stop
426                         if(!*s) break;
427
428                         // store the next word
429                         if(i < max_words) words[i++] = s;
430                         else break;
431                 }
432                 else s++;
433         }
434
435         // terminate the words
436         while(i < max_words) words[i++] = NULL;
437 }
438
439 pid_t tc_child_pid = 0;
440 void *tc_main(void *ptr)
441 {
442         if(ptr) { ; }
443
444         info("TC thread created with task id %d", gettid());
445
446         if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
447                 error("Cannot set pthread cancel type to DEFERRED.");
448
449         if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
450                 error("Cannot set pthread cancel state to ENABLE.");
451
452         struct rusage thread;
453         RRDSET *stcpu = NULL, *sttime = NULL;
454
455         char buffer[TC_LINE_MAX+1] = "";
456         char *words[MAX_WORDS] = { NULL };
457
458         uint32_t BEGIN_HASH = simple_hash("BEGIN");
459         uint32_t END_HASH = simple_hash("END");
460         uint32_t CLASS_HASH = simple_hash("class");
461         uint32_t SENT_HASH = simple_hash("Sent");
462         uint32_t SETDEVICENAME_HASH = simple_hash("SETDEVICENAME");
463         uint32_t SETDEVICEGROUP_HASH = simple_hash("SETDEVICEGROUP");
464         uint32_t SETCLASSNAME_HASH = simple_hash("SETCLASSNAME");
465         uint32_t WORKTIME_HASH = simple_hash("WORKTIME");
466 #ifdef DETACH_PLUGINS_FROM_NETDATA
467         uint32_t MYPID_HASH = simple_hash("MYPID");
468 #endif
469         uint32_t first_hash;
470
471         for(;1;) {
472                 FILE *fp;
473                 struct tc_device *device = NULL;
474                 struct tc_class *class = NULL;
475
476                 snprintf(buffer, TC_LINE_MAX, "exec %s %d", config_get("plugin:tc", "script to run to get tc values", PLUGINS_DIR "/tc-qos-helper.sh"), rrd_update_every);
477                 debug(D_TC_LOOP, "executing '%s'", buffer);
478                 // fp = popen(buffer, "r");
479                 fp = mypopen(buffer, &tc_child_pid);
480                 if(!fp) {
481                         error("TC: Cannot popen(\"%s\", \"r\").", buffer);
482                         return NULL;
483                 }
484
485                 while(fgets(buffer, TC_LINE_MAX, fp) != NULL) {
486                         buffer[TC_LINE_MAX] = '\0';
487                         // debug(D_TC_LOOP, "TC: read '%s'", buffer);
488
489                         tc_split_words(buffer, words, MAX_WORDS);
490                         if(!words[0] || !*words[0]) {
491                                 // debug(D_TC_LOOP, "empty line");
492                                 continue;
493                         }
494                         // else debug(D_TC_LOOP, "First word is '%s'", words[0]);
495
496                         first_hash = simple_hash(words[0]);
497
498                         if(first_hash == CLASS_HASH && strcmp(words[0], "class") == 0 && device) {
499                                 // debug(D_TC_LOOP, "CLASS line on class id='%s', parent='%s', parentid='%s', leaf='%s', leafid='%s'", words[2], words[3], words[4], words[5], words[6]);
500
501                                 if(words[1] && words[2] && words[3] && words[4] && (strcmp(words[3], "parent") == 0 || strcmp(words[3], "root") == 0)) {
502                                         // char *type     = words[1];  // the class: htb, fq_codel, etc
503                                         char *id       = words[2];      // the class major:minor
504                                         char *parent   = words[3];      // 'parent' or 'root'
505                                         char *parentid = words[4];      // the parent's id
506                                         char *leaf     = words[5];      // 'leaf'
507                                         char *leafid   = words[6];      // leafid
508
509                                         if(strcmp(parent, "root") == 0) {
510                                                 parentid = NULL;
511                                                 leafid = NULL;
512                                         }
513                                         else if(!leaf || strcmp(leaf, "leaf") != 0)
514                                                 leafid = NULL;
515
516                                         char leafbuf[20 + 1] = "";
517                                         if(leafid && leafid[strlen(leafid) - 1] == ':') {
518                                                 strncpy(leafbuf, leafid, 20 - 1);
519                                                 strcat(leafbuf, "1");
520                                                 leafid = leafbuf;
521                                         }
522
523                                         class = tc_class_add(device, id, parentid, leafid);
524                                 }
525                         }
526                         else if(first_hash == END_HASH && strcmp(words[0], "END") == 0) {
527                                 // debug(D_TC_LOOP, "END line");
528
529                                 if(device) {
530                                         if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL) != 0)
531                                                 error("Cannot set pthread cancel state to DISABLE.");
532
533                                         tc_device_commit(device);
534                                         // tc_device_free(device);
535                                         device = NULL;
536                                         class = NULL;
537
538                                         if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
539                                                 error("Cannot set pthread cancel state to ENABLE.");
540                                 }
541                         }
542                         else if(first_hash == BEGIN_HASH && strcmp(words[0], "BEGIN") == 0) {
543                                 // debug(D_TC_LOOP, "BEGIN line on device '%s'", words[1]);
544
545                                 if(device) {
546                                         // tc_device_free(device);
547                                         device = NULL;
548                                         class = NULL;
549                                 }
550
551                                 if(words[1] && *words[1]) {
552                                         device = tc_device_create(words[1]);
553                                         class = NULL;
554                                 }
555                         }
556                         else if(first_hash == SENT_HASH && strcmp(words[0], "Sent") == 0 && device && class) {
557                                 // debug(D_TC_LOOP, "SENT line '%s'", words[1]);
558                                 if(words[1] && *words[1]) {
559                                         class->bytes = atoll(words[1]);
560                                         class->updated = 1;
561                                 }
562                                 else class->bytes = 0;
563                         }
564                         else if(first_hash == SETDEVICENAME_HASH && strcmp(words[0], "SETDEVICENAME") == 0 && device) {
565                                 // debug(D_TC_LOOP, "SETDEVICENAME line '%s'", words[1]);
566                                 if(words[1] && *words[1]) tc_device_set_device_name(device, words[1]);
567                         }
568                         else if(first_hash == SETDEVICEGROUP_HASH && strcmp(words[0], "SETDEVICEGROUP") == 0 && device) {
569                                 // debug(D_TC_LOOP, "SETDEVICEGROUP line '%s'", words[1]);
570                                 if(words[1] && *words[1]) tc_device_set_device_family(device, words[1]);
571                         }
572                         else if(first_hash == SETCLASSNAME_HASH && strcmp(words[0], "SETCLASSNAME") == 0 && device) {
573                                 // debug(D_TC_LOOP, "SETCLASSNAME line '%s' '%s'", words[1], words[2]);
574                                 char *id    = words[1];
575                                 char *path  = words[2];
576                                 if(id && *id && path && *path) tc_device_set_class_name(device, id, path);
577                         }
578                         else if(first_hash == WORKTIME_HASH && strcmp(words[0], "WORKTIME") == 0) {
579                                 // debug(D_TC_LOOP, "WORKTIME line '%s' '%s'", words[1], words[2]);
580                                 getrusage(RUSAGE_THREAD, &thread);
581
582                                 if(!stcpu) stcpu = rrdset_find("netdata.plugin_tc_cpu");
583                                 if(!stcpu) {
584                                         stcpu = rrdset_create("netdata", "plugin_tc_cpu", NULL, "netdata", "NetData TC CPU usage", "milliseconds/s", 10000, rrd_update_every, RRDSET_TYPE_STACKED);
585                                         rrddim_add(stcpu, "user",  NULL,  1, 1000 * rrd_update_every, RRDDIM_INCREMENTAL);
586                                         rrddim_add(stcpu, "system", NULL, 1, 1000 * rrd_update_every, RRDDIM_INCREMENTAL);
587                                 }
588                                 else rrdset_next(stcpu);
589
590                                 rrddim_set(stcpu, "user"  , thread.ru_utime.tv_sec * 1000000ULL + thread.ru_utime.tv_usec);
591                                 rrddim_set(stcpu, "system", thread.ru_stime.tv_sec * 1000000ULL + thread.ru_stime.tv_usec);
592                                 rrdset_done(stcpu);
593
594                                 if(!sttime) stcpu = rrdset_find("netdata.plugin_tc_time");
595                                 if(!sttime) {
596                                         sttime = rrdset_create("netdata", "plugin_tc_time", NULL, "netdata", "NetData TC script execution", "milliseconds/run", 10001, rrd_update_every, RRDSET_TYPE_AREA);
597                                         rrddim_add(sttime, "run_time",  "run time",  1, 1, RRDDIM_ABSOLUTE);
598                                 }
599                                 else rrdset_next(sttime);
600
601                                 rrddim_set(sttime, "run_time", atoll(words[1]));
602                                 rrdset_done(sttime);
603
604                         }
605 #ifdef DETACH_PLUGINS_FROM_NETDATA
606                         else if(first_hash == MYPID_HASH && (strcmp(words[0], "MYPID") == 0)) {
607                                 // debug(D_TC_LOOP, "MYPID line '%s'", words[1]);
608                                 char *id = words[1];
609                                 pid_t pid = atol(id);
610
611                                 if(pid) tc_child_pid = pid;
612
613                                 debug(D_TC_LOOP, "TC: Child PID is %d.", tc_child_pid);
614                         }
615 #endif
616                         //else {
617                         //      debug(D_TC_LOOP, "IGNORED line");
618                         //}
619                 }
620                 mypclose(fp, tc_child_pid);
621                 tc_child_pid = 0;
622
623                 if(device) {
624                         // tc_device_free(device);
625                         device = NULL;
626                         class = NULL;
627                 }
628
629                 sleep(rrd_update_every);
630         }
631
632         return NULL;
633 }
634