plugin_tc.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "daemon/common.h"
  3. #define RRD_TYPE_TC "tc"
  4. #define PLUGIN_TC_NAME "tc.plugin"
  5. // ----------------------------------------------------------------------------
  6. // /sbin/tc processor
  7. // this requires the script plugins.d/tc-qos-helper.sh
  8. #define TC_LINE_MAX 1024
  9. struct tc_class {
  10. avl_t avl;
  11. char *id;
  12. uint32_t hash;
  13. char *name;
  14. char *leafid;
  15. uint32_t leaf_hash;
  16. char *parentid;
  17. uint32_t parent_hash;
  18. char hasparent;
  19. char isleaf;
  20. char isqdisc;
  21. char render;
  22. unsigned long long bytes;
  23. unsigned long long packets;
  24. unsigned long long dropped;
  25. unsigned long long overlimits;
  26. unsigned long long requeues;
  27. unsigned long long lended;
  28. unsigned long long borrowed;
  29. unsigned long long giants;
  30. unsigned long long tokens;
  31. unsigned long long ctokens;
  32. RRDDIM *rd_bytes;
  33. RRDDIM *rd_packets;
  34. RRDDIM *rd_dropped;
  35. RRDDIM *rd_tokens;
  36. RRDDIM *rd_ctokens;
  37. char name_updated;
  38. char updated; // updated bytes
  39. int unupdated; // the number of times, this has been found un-updated
  40. struct tc_class *next;
  41. struct tc_class *prev;
  42. };
  43. struct tc_device {
  44. avl_t avl;
  45. char *id;
  46. uint32_t hash;
  47. char *name;
  48. char *family;
  49. char name_updated;
  50. char family_updated;
  51. char enabled;
  52. char enabled_bytes;
  53. char enabled_packets;
  54. char enabled_dropped;
  55. char enabled_tokens;
  56. char enabled_ctokens;
  57. char enabled_all_classes_qdiscs;
  58. RRDSET *st_bytes;
  59. RRDSET *st_packets;
  60. RRDSET *st_dropped;
  61. RRDSET *st_tokens;
  62. RRDSET *st_ctokens;
  63. avl_tree_type classes_index;
  64. struct tc_class *classes;
  65. struct tc_class *last_class;
  66. struct tc_device *next;
  67. struct tc_device *prev;
  68. };
  69. struct tc_device *tc_device_root = NULL;
  70. // ----------------------------------------------------------------------------
  71. // tc_device index
  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. avl_tree_type tc_device_root_index = {
  78. NULL,
  79. tc_device_compare
  80. };
  81. #define tc_device_index_add(st) (struct tc_device *)avl_insert(&tc_device_root_index, (avl_t *)(st))
  82. #define tc_device_index_del(st) (struct tc_device *)avl_remove(&tc_device_root_index, (avl_t *)(st))
  83. static inline struct tc_device *tc_device_index_find(const char *id, uint32_t hash) {
  84. struct tc_device tmp;
  85. tmp.id = (char *)id;
  86. tmp.hash = (hash)?hash:simple_hash(tmp.id);
  87. return (struct tc_device *)avl_search(&(tc_device_root_index), (avl_t *)&tmp);
  88. }
  89. // ----------------------------------------------------------------------------
  90. // tc_class index
  91. static int tc_class_compare(void* a, void* b) {
  92. if(((struct tc_class *)a)->hash < ((struct tc_class *)b)->hash) return -1;
  93. else if(((struct tc_class *)a)->hash > ((struct tc_class *)b)->hash) return 1;
  94. else return strcmp(((struct tc_class *)a)->id, ((struct tc_class *)b)->id);
  95. }
  96. #define tc_class_index_add(st, rd) (struct tc_class *)avl_insert(&((st)->classes_index), (avl_t *)(rd))
  97. #define tc_class_index_del(st, rd) (struct tc_class *)avl_remove(&((st)->classes_index), (avl_t *)(rd))
  98. static inline struct tc_class *tc_class_index_find(struct tc_device *st, const char *id, uint32_t hash) {
  99. struct tc_class tmp;
  100. tmp.id = (char *)id;
  101. tmp.hash = (hash)?hash:simple_hash(tmp.id);
  102. return (struct tc_class *)avl_search(&(st->classes_index), (avl_t *) &tmp);
  103. }
  104. // ----------------------------------------------------------------------------
  105. static inline void tc_class_free(struct tc_device *n, struct tc_class *c) {
  106. if(c == n->classes) {
  107. if(likely(c->next))
  108. n->classes = c->next;
  109. else
  110. n->classes = c->prev;
  111. }
  112. if(c == n->last_class) {
  113. if(unlikely(c->next))
  114. n->last_class = c->next;
  115. else
  116. n->last_class = c->prev;
  117. }
  118. if(c->next) c->next->prev = c->prev;
  119. if(c->prev) c->prev->next = c->next;
  120. debug(D_TC_LOOP, "Removing from device '%s' class '%s', parentid '%s', leafid '%s', unused=%d", n->id, c->id, c->parentid?c->parentid:"", c->leafid?c->leafid:"", c->unupdated);
  121. if(unlikely(tc_class_index_del(n, c) != c))
  122. error("plugin_tc: INTERNAL ERROR: attempt remove class '%s' from device '%s': removed a different calls", c->id, n->id);
  123. freez(c->id);
  124. freez(c->name);
  125. freez(c->leafid);
  126. freez(c->parentid);
  127. freez(c);
  128. }
  129. static inline void tc_device_classes_cleanup(struct tc_device *d) {
  130. static int cleanup_every = 999;
  131. if(unlikely(cleanup_every > 0)) {
  132. cleanup_every = (int) config_get_number("plugin:tc", "cleanup unused classes every", 120);
  133. if(cleanup_every < 0) cleanup_every = -cleanup_every;
  134. }
  135. d->name_updated = 0;
  136. d->family_updated = 0;
  137. struct tc_class *c = d->classes;
  138. while(c) {
  139. if(unlikely(cleanup_every && c->unupdated >= cleanup_every)) {
  140. struct tc_class *nc = c->next;
  141. tc_class_free(d, c);
  142. c = nc;
  143. }
  144. else {
  145. c->updated = 0;
  146. c->name_updated = 0;
  147. c = c->next;
  148. }
  149. }
  150. }
  151. static inline void tc_device_commit(struct tc_device *d) {
  152. static int enable_new_interfaces = -1, enable_bytes = -1, enable_packets = -1, enable_dropped = -1, enable_tokens = -1, enable_ctokens = -1, enabled_all_classes_qdiscs = -1;
  153. if(unlikely(enable_new_interfaces == -1)) {
  154. enable_new_interfaces = config_get_boolean_ondemand("plugin:tc", "enable new interfaces detected at runtime", CONFIG_BOOLEAN_YES);
  155. enable_bytes = config_get_boolean_ondemand("plugin:tc", "enable traffic charts for all interfaces", CONFIG_BOOLEAN_AUTO);
  156. enable_packets = config_get_boolean_ondemand("plugin:tc", "enable packets charts for all interfaces", CONFIG_BOOLEAN_AUTO);
  157. enable_dropped = config_get_boolean_ondemand("plugin:tc", "enable dropped charts for all interfaces", CONFIG_BOOLEAN_AUTO);
  158. enable_tokens = config_get_boolean_ondemand("plugin:tc", "enable tokens charts for all interfaces", CONFIG_BOOLEAN_NO);
  159. enable_ctokens = config_get_boolean_ondemand("plugin:tc", "enable ctokens charts for all interfaces", CONFIG_BOOLEAN_NO);
  160. enabled_all_classes_qdiscs = config_get_boolean_ondemand("plugin:tc", "enable show all classes and qdiscs for all interfaces", CONFIG_BOOLEAN_NO);
  161. }
  162. if(unlikely(d->enabled == (char)-1)) {
  163. char var_name[CONFIG_MAX_NAME + 1];
  164. snprintfz(var_name, CONFIG_MAX_NAME, "qos for %s", d->id);
  165. d->enabled = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_new_interfaces);
  166. snprintfz(var_name, CONFIG_MAX_NAME, "traffic chart for %s", d->id);
  167. d->enabled_bytes = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_bytes);
  168. snprintfz(var_name, CONFIG_MAX_NAME, "packets chart for %s", d->id);
  169. d->enabled_packets = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_packets);
  170. snprintfz(var_name, CONFIG_MAX_NAME, "dropped packets chart for %s", d->id);
  171. d->enabled_dropped = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_dropped);
  172. snprintfz(var_name, CONFIG_MAX_NAME, "tokens chart for %s", d->id);
  173. d->enabled_tokens = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_tokens);
  174. snprintfz(var_name, CONFIG_MAX_NAME, "ctokens chart for %s", d->id);
  175. d->enabled_ctokens = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_ctokens);
  176. snprintfz(var_name, CONFIG_MAX_NAME, "show all classes for %s", d->id);
  177. d->enabled_all_classes_qdiscs = (char)config_get_boolean_ondemand("plugin:tc", var_name, enabled_all_classes_qdiscs);
  178. }
  179. // we only need to add leaf classes
  180. struct tc_class *c, *x /*, *root = NULL */;
  181. unsigned long long bytes_sum = 0, packets_sum = 0, dropped_sum = 0, tokens_sum = 0, ctokens_sum = 0;
  182. int active_nodes = 0, updated_classes = 0, updated_qdiscs = 0;
  183. // prepare all classes
  184. // we set reasonable defaults for the rest of the code below
  185. for(c = d->classes ; c ; c = c->next) {
  186. c->render = 0; // do not render this class
  187. c->isleaf = 1; // this is a leaf class
  188. c->hasparent = 0; // without a parent
  189. if(unlikely(!c->updated))
  190. c->unupdated++; // increase its unupdated counter
  191. else {
  192. c->unupdated = 0; // reset its unupdated counter
  193. // count how many of each kind
  194. if(c->isqdisc)
  195. updated_qdiscs++;
  196. else
  197. updated_classes++;
  198. }
  199. }
  200. if(unlikely(!d->enabled || (!updated_classes && !updated_qdiscs))) {
  201. debug(D_TC_LOOP, "TC: Ignoring TC device '%s'. It is not enabled/updated.", d->name?d->name:d->id);
  202. tc_device_classes_cleanup(d);
  203. return;
  204. }
  205. if(unlikely(updated_classes && updated_qdiscs)) {
  206. error("TC: device '%s' has active both classes (%d) and qdiscs (%d). Will render only qdiscs.", d->id, updated_classes, updated_qdiscs);
  207. // set all classes to !updated
  208. for(c = d->classes ; c ; c = c->next)
  209. if(unlikely(!c->isqdisc && c->updated))
  210. c->updated = 0;
  211. updated_classes = 0;
  212. }
  213. // mark the classes as leafs and parents
  214. //
  215. // TC is hierarchical:
  216. // - classes can have other classes in them
  217. // - the same is true for qdiscs (i.e. qdiscs have classes, that have other qdiscs)
  218. //
  219. // we need to present a chart with leaf nodes only, so that the sum
  220. // of all dimensions of the chart, will be the total utilization
  221. // of the interface.
  222. //
  223. // here we try to find the ones we need to report
  224. // by default all nodes are marked with: isleaf = 1 (see above)
  225. //
  226. // so, here we remove the isleaf flag from nodes in the middle
  227. // and we add the hasparent flag to leaf nodes we found their parent
  228. if(likely(!d->enabled_all_classes_qdiscs)) {
  229. for(c = d->classes; c; c = c->next) {
  230. if(unlikely(!c->updated)) continue;
  231. //debug(D_TC_LOOP, "TC: In device '%s', %s '%s' has leafid: '%s' and parentid '%s'.",
  232. // d->id,
  233. // c->isqdisc?"qdisc":"class",
  234. // c->id,
  235. // c->leafid?c->leafid:"NULL",
  236. // c->parentid?c->parentid:"NULL");
  237. // find if c is leaf or not
  238. for(x = d->classes; x; x = x->next) {
  239. if(unlikely(!x->updated || c == x || !x->parentid)) continue;
  240. // classes have both parentid and leafid
  241. // qdiscs have only parentid
  242. // the following works for both (it is an OR)
  243. if((c->hash == x->parent_hash && strcmp(c->id, x->parentid) == 0) ||
  244. (c->leafid && c->leaf_hash == x->parent_hash && strcmp(c->leafid, x->parentid) == 0)) {
  245. // debug(D_TC_LOOP, "TC: In device '%s', %s '%s' (leafid: '%s') has as leaf %s '%s' (parentid: '%s').", d->name?d->name:d->id, c->isqdisc?"qdisc":"class", c->name?c->name:c->id, c->leafid?c->leafid:c->id, x->isqdisc?"qdisc":"class", x->name?x->name:x->id, x->parentid?x->parentid:x->id);
  246. c->isleaf = 0;
  247. x->hasparent = 1;
  248. }
  249. }
  250. }
  251. }
  252. for(c = d->classes ; c ; c = c->next) {
  253. if(unlikely(!c->updated)) continue;
  254. // debug(D_TC_LOOP, "TC: device '%s', %s '%s' isleaf=%d, hasparent=%d", d->id, (c->isqdisc)?"qdisc":"class", c->id, c->isleaf, c->hasparent);
  255. if(unlikely((c->isleaf && c->hasparent) || d->enabled_all_classes_qdiscs)) {
  256. c->render = 1;
  257. active_nodes++;
  258. bytes_sum += c->bytes;
  259. packets_sum += c->packets;
  260. dropped_sum += c->dropped;
  261. tokens_sum += c->tokens;
  262. ctokens_sum += c->ctokens;
  263. }
  264. //if(unlikely(!c->hasparent)) {
  265. // if(root) error("TC: multiple root class/qdisc for device '%s' (old: '%s', new: '%s')", d->id, root->id, c->id);
  266. // root = c;
  267. // debug(D_TC_LOOP, "TC: found root class/qdisc '%s'", root->id);
  268. //}
  269. }
  270. #ifdef NETDATA_INTERNAL_CHECKS
  271. // dump all the list to see what we know
  272. if(unlikely(debug_flags & D_TC_LOOP)) {
  273. for(c = d->classes ; c ; c = c->next) {
  274. if(c->render) debug(D_TC_LOOP, "TC: final nodes dump for '%s': class %s, OK", d->name, c->id);
  275. else debug(D_TC_LOOP, "TC: final nodes dump for '%s': class %s, IGNORE (updated: %d, isleaf: %d, hasparent: %d, parent: %s)", d->name?d->name:d->id, c->id, c->updated, c->isleaf, c->hasparent, c->parentid?c->parentid:"(unset)");
  276. }
  277. }
  278. #endif
  279. if(unlikely(!active_nodes)) {
  280. debug(D_TC_LOOP, "TC: Ignoring TC device '%s'. No useful classes/qdiscs.", d->name?d->name:d->id);
  281. tc_device_classes_cleanup(d);
  282. return;
  283. }
  284. debug(D_TC_LOOP, "TC: evaluating TC device '%s'. enabled = %d/%d (bytes: %d/%d, packets: %d/%d, dropped: %d/%d, tokens: %d/%d, ctokens: %d/%d, all_classes_qdiscs: %d/%d), classes: (bytes = %llu, packets = %llu, dropped = %llu, tokens = %llu, ctokens = %llu).",
  285. d->name?d->name:d->id,
  286. d->enabled, enable_new_interfaces,
  287. d->enabled_bytes, enable_bytes,
  288. d->enabled_packets, enable_packets,
  289. d->enabled_dropped, enable_dropped,
  290. d->enabled_tokens, enable_tokens,
  291. d->enabled_ctokens, enable_ctokens,
  292. d->enabled_all_classes_qdiscs, enabled_all_classes_qdiscs,
  293. bytes_sum,
  294. packets_sum,
  295. dropped_sum,
  296. tokens_sum,
  297. ctokens_sum
  298. );
  299. // --------------------------------------------------------------------
  300. // bytes
  301. if(d->enabled_bytes == CONFIG_BOOLEAN_YES || (d->enabled_bytes == CONFIG_BOOLEAN_AUTO &&
  302. (bytes_sum ||
  303. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  304. d->enabled_bytes = CONFIG_BOOLEAN_YES;
  305. if(unlikely(!d->st_bytes))
  306. d->st_bytes = rrdset_create_localhost(
  307. RRD_TYPE_TC
  308. , d->id
  309. , d->name ? d->name : d->id
  310. , d->family ? d->family : d->id
  311. , RRD_TYPE_TC ".qos"
  312. , "Class Usage"
  313. , "kilobits/s"
  314. , PLUGIN_TC_NAME
  315. , NULL
  316. , NETDATA_CHART_PRIO_TC_QOS
  317. , localhost->rrd_update_every
  318. , d->enabled_all_classes_qdiscs ? RRDSET_TYPE_LINE : RRDSET_TYPE_STACKED
  319. );
  320. else {
  321. rrdset_next(d->st_bytes);
  322. if(unlikely(d->name_updated)) rrdset_set_name(d->st_bytes, d->name);
  323. // TODO
  324. // update the family
  325. }
  326. for(c = d->classes ; c ; c = c->next) {
  327. if(unlikely(!c->render)) continue;
  328. if(unlikely(!c->rd_bytes))
  329. c->rd_bytes = rrddim_add(d->st_bytes, c->id, c->name?c->name:c->id, 8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL);
  330. else if(unlikely(c->name_updated))
  331. rrddim_set_name(d->st_bytes, c->rd_bytes, c->name);
  332. rrddim_set_by_pointer(d->st_bytes, c->rd_bytes, c->bytes);
  333. }
  334. rrdset_done(d->st_bytes);
  335. }
  336. // --------------------------------------------------------------------
  337. // packets
  338. if(d->enabled_packets == CONFIG_BOOLEAN_YES || (d->enabled_packets == CONFIG_BOOLEAN_AUTO &&
  339. (packets_sum ||
  340. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  341. d->enabled_packets = CONFIG_BOOLEAN_YES;
  342. if(unlikely(!d->st_packets)) {
  343. char id[RRD_ID_LENGTH_MAX + 1];
  344. char name[RRD_ID_LENGTH_MAX + 1];
  345. snprintfz(id, RRD_ID_LENGTH_MAX, "%s_packets", d->id);
  346. snprintfz(name, RRD_ID_LENGTH_MAX, "%s_packets", d->name?d->name:d->id);
  347. d->st_packets = rrdset_create_localhost(
  348. RRD_TYPE_TC
  349. , id
  350. , name
  351. , d->family ? d->family : d->id
  352. , RRD_TYPE_TC ".qos_packets"
  353. , "Class Packets"
  354. , "packets/s"
  355. , PLUGIN_TC_NAME
  356. , NULL
  357. , NETDATA_CHART_PRIO_TC_QOS_PACKETS
  358. , localhost->rrd_update_every
  359. , d->enabled_all_classes_qdiscs ? RRDSET_TYPE_LINE : RRDSET_TYPE_STACKED
  360. );
  361. }
  362. else {
  363. rrdset_next(d->st_packets);
  364. if(unlikely(d->name_updated)) {
  365. char name[RRD_ID_LENGTH_MAX + 1];
  366. snprintfz(name, RRD_ID_LENGTH_MAX, "%s_packets", d->name?d->name:d->id);
  367. rrdset_set_name(d->st_packets, name);
  368. }
  369. // TODO
  370. // update the family
  371. }
  372. for(c = d->classes ; c ; c = c->next) {
  373. if(unlikely(!c->render)) continue;
  374. if(unlikely(!c->rd_packets))
  375. c->rd_packets = rrddim_add(d->st_packets, c->id, c->name?c->name:c->id, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  376. else if(unlikely(c->name_updated))
  377. rrddim_set_name(d->st_packets, c->rd_packets, c->name);
  378. rrddim_set_by_pointer(d->st_packets, c->rd_packets, c->packets);
  379. }
  380. rrdset_done(d->st_packets);
  381. }
  382. // --------------------------------------------------------------------
  383. // dropped
  384. if(d->enabled_dropped == CONFIG_BOOLEAN_YES || (d->enabled_dropped == CONFIG_BOOLEAN_AUTO &&
  385. (dropped_sum ||
  386. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  387. d->enabled_dropped = CONFIG_BOOLEAN_YES;
  388. if(unlikely(!d->st_dropped)) {
  389. char id[RRD_ID_LENGTH_MAX + 1];
  390. char name[RRD_ID_LENGTH_MAX + 1];
  391. snprintfz(id, RRD_ID_LENGTH_MAX, "%s_dropped", d->id);
  392. snprintfz(name, RRD_ID_LENGTH_MAX, "%s_dropped", d->name?d->name:d->id);
  393. d->st_dropped = rrdset_create_localhost(
  394. RRD_TYPE_TC
  395. , id
  396. , name
  397. , d->family ? d->family : d->id
  398. , RRD_TYPE_TC ".qos_dropped"
  399. , "Class Dropped Packets"
  400. , "packets/s"
  401. , PLUGIN_TC_NAME
  402. , NULL
  403. , NETDATA_CHART_PRIO_TC_QOS_DROPPED
  404. , localhost->rrd_update_every
  405. , d->enabled_all_classes_qdiscs ? RRDSET_TYPE_LINE : RRDSET_TYPE_STACKED
  406. );
  407. }
  408. else {
  409. rrdset_next(d->st_dropped);
  410. if(unlikely(d->name_updated)) {
  411. char name[RRD_ID_LENGTH_MAX + 1];
  412. snprintfz(name, RRD_ID_LENGTH_MAX, "%s_dropped", d->name?d->name:d->id);
  413. rrdset_set_name(d->st_dropped, name);
  414. }
  415. // TODO
  416. // update the family
  417. }
  418. for(c = d->classes ; c ; c = c->next) {
  419. if(unlikely(!c->render)) continue;
  420. if(unlikely(!c->rd_dropped))
  421. c->rd_dropped = rrddim_add(d->st_dropped, c->id, c->name?c->name:c->id, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  422. else if(unlikely(c->name_updated))
  423. rrddim_set_name(d->st_dropped, c->rd_dropped, c->name);
  424. rrddim_set_by_pointer(d->st_dropped, c->rd_dropped, c->dropped);
  425. }
  426. rrdset_done(d->st_dropped);
  427. }
  428. // --------------------------------------------------------------------
  429. // tokens
  430. if(d->enabled_tokens == CONFIG_BOOLEAN_YES || (d->enabled_tokens == CONFIG_BOOLEAN_AUTO &&
  431. (tokens_sum ||
  432. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  433. d->enabled_tokens = CONFIG_BOOLEAN_YES;
  434. if(unlikely(!d->st_tokens)) {
  435. char id[RRD_ID_LENGTH_MAX + 1];
  436. char name[RRD_ID_LENGTH_MAX + 1];
  437. snprintfz(id, RRD_ID_LENGTH_MAX, "%s_tokens", d->id);
  438. snprintfz(name, RRD_ID_LENGTH_MAX, "%s_tokens", d->name?d->name:d->id);
  439. d->st_tokens = rrdset_create_localhost(
  440. RRD_TYPE_TC
  441. , id
  442. , name
  443. , d->family ? d->family : d->id
  444. , RRD_TYPE_TC ".qos_tokens"
  445. , "Class Tokens"
  446. , "tokens"
  447. , PLUGIN_TC_NAME
  448. , NULL
  449. , NETDATA_CHART_PRIO_TC_QOS_TOKENS
  450. , localhost->rrd_update_every
  451. , RRDSET_TYPE_LINE
  452. );
  453. }
  454. else {
  455. rrdset_next(d->st_tokens);
  456. if(unlikely(d->name_updated)) {
  457. char name[RRD_ID_LENGTH_MAX + 1];
  458. snprintfz(name, RRD_ID_LENGTH_MAX, "%s_tokens", d->name?d->name:d->id);
  459. rrdset_set_name(d->st_tokens, name);
  460. }
  461. // TODO
  462. // update the family
  463. }
  464. for(c = d->classes ; c ; c = c->next) {
  465. if(unlikely(!c->render)) continue;
  466. if(unlikely(!c->rd_tokens)) {
  467. c->rd_tokens = rrddim_add(d->st_tokens, c->id, c->name?c->name:c->id, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  468. }
  469. else if(unlikely(c->name_updated))
  470. rrddim_set_name(d->st_tokens, c->rd_tokens, c->name);
  471. rrddim_set_by_pointer(d->st_tokens, c->rd_tokens, c->tokens);
  472. }
  473. rrdset_done(d->st_tokens);
  474. }
  475. // --------------------------------------------------------------------
  476. // ctokens
  477. if(d->enabled_ctokens == CONFIG_BOOLEAN_YES || (d->enabled_ctokens == CONFIG_BOOLEAN_AUTO &&
  478. (ctokens_sum ||
  479. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  480. d->enabled_ctokens = CONFIG_BOOLEAN_YES;
  481. if(unlikely(!d->st_ctokens)) {
  482. char id[RRD_ID_LENGTH_MAX + 1];
  483. char name[RRD_ID_LENGTH_MAX + 1];
  484. snprintfz(id, RRD_ID_LENGTH_MAX, "%s_ctokens", d->id);
  485. snprintfz(name, RRD_ID_LENGTH_MAX, "%s_ctokens", d->name?d->name:d->id);
  486. d->st_ctokens = rrdset_create_localhost(
  487. RRD_TYPE_TC
  488. , id
  489. , name
  490. , d->family ? d->family : d->id
  491. , RRD_TYPE_TC ".qos_ctokens"
  492. , "Class cTokens"
  493. , "ctokens"
  494. , PLUGIN_TC_NAME
  495. , NULL
  496. , NETDATA_CHART_PRIO_TC_QOS_CTOKENS
  497. , localhost->rrd_update_every
  498. , RRDSET_TYPE_LINE
  499. );
  500. }
  501. else {
  502. debug(D_TC_LOOP, "TC: Updating _ctokens chart for device '%s'", d->name?d->name:d->id);
  503. rrdset_next(d->st_ctokens);
  504. if(unlikely(d->name_updated)) {
  505. char name[RRD_ID_LENGTH_MAX + 1];
  506. snprintfz(name, RRD_ID_LENGTH_MAX, "%s_ctokens", d->name?d->name:d->id);
  507. rrdset_set_name(d->st_ctokens, name);
  508. }
  509. // TODO
  510. // update the family
  511. }
  512. for(c = d->classes ; c ; c = c->next) {
  513. if(unlikely(!c->render)) continue;
  514. if(unlikely(!c->rd_ctokens))
  515. c->rd_ctokens = rrddim_add(d->st_ctokens, c->id, c->name?c->name:c->id, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  516. else if(unlikely(c->name_updated))
  517. rrddim_set_name(d->st_ctokens, c->rd_ctokens, c->name);
  518. rrddim_set_by_pointer(d->st_ctokens, c->rd_ctokens, c->ctokens);
  519. }
  520. rrdset_done(d->st_ctokens);
  521. }
  522. tc_device_classes_cleanup(d);
  523. }
  524. static inline void tc_device_set_class_name(struct tc_device *d, char *id, char *name) {
  525. if(unlikely(!name || !*name)) return;
  526. struct tc_class *c = tc_class_index_find(d, id, 0);
  527. if(likely(c)) {
  528. if(likely(c->name)) {
  529. if(!strcmp(c->name, name)) return;
  530. freez(c->name);
  531. c->name = NULL;
  532. }
  533. if(likely(name && *name && strcmp(c->id, name) != 0)) {
  534. debug(D_TC_LOOP, "TC: Setting device '%s', class '%s' name to '%s'", d->id, id, name);
  535. c->name = strdupz(name);
  536. c->name_updated = 1;
  537. }
  538. }
  539. }
  540. static inline void tc_device_set_device_name(struct tc_device *d, char *name) {
  541. if(unlikely(!name || !*name)) return;
  542. if(d->name) {
  543. if(!strcmp(d->name, name)) return;
  544. freez(d->name);
  545. d->name = NULL;
  546. }
  547. if(likely(name && *name && strcmp(d->id, name) != 0)) {
  548. debug(D_TC_LOOP, "TC: Setting device '%s' name to '%s'", d->id, name);
  549. d->name = strdupz(name);
  550. d->name_updated = 1;
  551. }
  552. }
  553. static inline void tc_device_set_device_family(struct tc_device *d, char *family) {
  554. freez(d->family);
  555. d->family = NULL;
  556. if(likely(family && *family && strcmp(d->id, family) != 0)) {
  557. debug(D_TC_LOOP, "TC: Setting device '%s' family to '%s'", d->id, family);
  558. d->family = strdupz(family);
  559. d->family_updated = 1;
  560. }
  561. // no need for null termination - it is already null
  562. }
  563. static inline struct tc_device *tc_device_create(char *id)
  564. {
  565. struct tc_device *d = tc_device_index_find(id, 0);
  566. if(!d) {
  567. debug(D_TC_LOOP, "TC: Creating device '%s'", id);
  568. d = callocz(1, sizeof(struct tc_device));
  569. d->id = strdupz(id);
  570. d->hash = simple_hash(d->id);
  571. d->enabled = (char)-1;
  572. avl_init(&d->classes_index, tc_class_compare);
  573. if(unlikely(tc_device_index_add(d) != d))
  574. error("plugin_tc: INTERNAL ERROR: removing device '%s' removed a different device.", d->id);
  575. if(!tc_device_root) {
  576. tc_device_root = d;
  577. }
  578. else {
  579. d->next = tc_device_root;
  580. tc_device_root->prev = d;
  581. tc_device_root = d;
  582. }
  583. }
  584. return(d);
  585. }
  586. static inline struct tc_class *tc_class_add(struct tc_device *n, char *id, char qdisc, char *parentid, char *leafid)
  587. {
  588. struct tc_class *c = tc_class_index_find(n, id, 0);
  589. if(!c) {
  590. debug(D_TC_LOOP, "TC: Creating in device '%s', class id '%s', parentid '%s', leafid '%s'", n->id, id, parentid?parentid:"", leafid?leafid:"");
  591. c = callocz(1, sizeof(struct tc_class));
  592. if(unlikely(!n->classes))
  593. n->classes = c;
  594. else if(likely(n->last_class)) {
  595. n->last_class->next = c;
  596. c->prev = n->last_class;
  597. }
  598. n->last_class = c;
  599. c->id = strdupz(id);
  600. c->hash = simple_hash(c->id);
  601. c->isqdisc = qdisc;
  602. if(parentid && *parentid) {
  603. c->parentid = strdupz(parentid);
  604. c->parent_hash = simple_hash(c->parentid);
  605. }
  606. if(leafid && *leafid) {
  607. c->leafid = strdupz(leafid);
  608. c->leaf_hash = simple_hash(c->leafid);
  609. }
  610. if(unlikely(tc_class_index_add(n, c) != c))
  611. error("plugin_tc: INTERNAL ERROR: attempt index class '%s' on device '%s': already exists", c->id, n->id);
  612. }
  613. return(c);
  614. }
  615. static inline void tc_device_free(struct tc_device *n)
  616. {
  617. if(n->next) n->next->prev = n->prev;
  618. if(n->prev) n->prev->next = n->next;
  619. if(tc_device_root == n) {
  620. if(n->next) tc_device_root = n->next;
  621. else tc_device_root = n->prev;
  622. }
  623. if(unlikely(tc_device_index_del(n) != n))
  624. error("plugin_tc: INTERNAL ERROR: removing device '%s' removed a different device.", n->id);
  625. while(n->classes) tc_class_free(n, n->classes);
  626. freez(n->id);
  627. freez(n->name);
  628. freez(n->family);
  629. freez(n);
  630. }
  631. static inline void tc_device_free_all()
  632. {
  633. while(tc_device_root)
  634. tc_device_free(tc_device_root);
  635. }
  636. #define PLUGINSD_MAX_WORDS 20
  637. static inline int tc_space(char c) {
  638. switch(c) {
  639. case ' ':
  640. case '\t':
  641. case '\r':
  642. case '\n':
  643. return 1;
  644. default:
  645. return 0;
  646. }
  647. }
  648. static inline void tc_split_words(char *str, char **words, int max_words) {
  649. char *s = str;
  650. int i = 0;
  651. // skip all white space
  652. while(tc_space(*s)) s++;
  653. // store the first word
  654. words[i++] = s;
  655. // while we have something
  656. while(*s) {
  657. // if it is a space
  658. if(unlikely(tc_space(*s))) {
  659. // terminate the word
  660. *s++ = '\0';
  661. // skip all white space
  662. while(tc_space(*s)) s++;
  663. // if we reached the end, stop
  664. if(!*s) break;
  665. // store the next word
  666. if(i < max_words) words[i++] = s;
  667. else break;
  668. }
  669. else s++;
  670. }
  671. // terminate the words
  672. while(i < max_words) words[i++] = NULL;
  673. }
  674. static pid_t tc_child_pid = 0;
  675. static void tc_main_cleanup(void *ptr) {
  676. struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
  677. static_thread->enabled = NETDATA_MAIN_THREAD_EXITING;
  678. info("cleaning up...");
  679. if(tc_child_pid) {
  680. info("TC: killing with SIGTERM tc-qos-helper process %d", tc_child_pid);
  681. if(killpid(tc_child_pid) != -1) {
  682. siginfo_t info;
  683. info("TC: waiting for tc plugin child process pid %d to exit...", tc_child_pid);
  684. waitid(P_PID, (id_t) tc_child_pid, &info, WEXITED);
  685. }
  686. tc_child_pid = 0;
  687. }
  688. static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
  689. }
  690. void *tc_main(void *ptr) {
  691. netdata_thread_cleanup_push(tc_main_cleanup, ptr);
  692. struct rusage thread;
  693. char command[FILENAME_MAX + 1];
  694. char *words[PLUGINSD_MAX_WORDS] = { NULL };
  695. uint32_t BEGIN_HASH = simple_hash("BEGIN");
  696. uint32_t END_HASH = simple_hash("END");
  697. uint32_t QDISC_HASH = simple_hash("qdisc");
  698. uint32_t CLASS_HASH = simple_hash("class");
  699. uint32_t SENT_HASH = simple_hash("Sent");
  700. uint32_t LENDED_HASH = simple_hash("lended:");
  701. uint32_t TOKENS_HASH = simple_hash("tokens:");
  702. uint32_t SETDEVICENAME_HASH = simple_hash("SETDEVICENAME");
  703. uint32_t SETDEVICEGROUP_HASH = simple_hash("SETDEVICEGROUP");
  704. uint32_t SETCLASSNAME_HASH = simple_hash("SETCLASSNAME");
  705. uint32_t WORKTIME_HASH = simple_hash("WORKTIME");
  706. uint32_t first_hash;
  707. snprintfz(command, TC_LINE_MAX, "%s/tc-qos-helper.sh", netdata_configured_primary_plugins_dir);
  708. char *tc_script = config_get("plugin:tc", "script to run to get tc values", command);
  709. while(!netdata_exit) {
  710. FILE *fp;
  711. struct tc_device *device = NULL;
  712. struct tc_class *class = NULL;
  713. snprintfz(command, TC_LINE_MAX, "exec %s %d", tc_script, localhost->rrd_update_every);
  714. debug(D_TC_LOOP, "executing '%s'", command);
  715. fp = mypopen(command, (pid_t *)&tc_child_pid);
  716. if(unlikely(!fp)) {
  717. error("TC: Cannot popen(\"%s\", \"r\").", command);
  718. goto cleanup;
  719. }
  720. char buffer[TC_LINE_MAX+1] = "";
  721. while(fgets(buffer, TC_LINE_MAX, fp) != NULL) {
  722. if(unlikely(netdata_exit)) break;
  723. buffer[TC_LINE_MAX] = '\0';
  724. // debug(D_TC_LOOP, "TC: read '%s'", buffer);
  725. tc_split_words(buffer, words, PLUGINSD_MAX_WORDS);
  726. if(unlikely(!words[0] || !*words[0])) {
  727. // debug(D_TC_LOOP, "empty line");
  728. continue;
  729. }
  730. // else debug(D_TC_LOOP, "First word is '%s'", words[0]);
  731. first_hash = simple_hash(words[0]);
  732. if(unlikely(device && ((first_hash == CLASS_HASH && strcmp(words[0], "class") == 0) || (first_hash == QDISC_HASH && strcmp(words[0], "qdisc") == 0)))) {
  733. // 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]);
  734. char *type = words[1]; // the class/qdisc type: htb, fq_codel, etc
  735. char *id = words[2]; // the class/qdisc major:minor
  736. char *parent = words[3]; // the word 'parent' or 'root'
  737. char *parentid = words[4]; // parentid
  738. char *leaf = words[5]; // the word 'leaf'
  739. char *leafid = words[6]; // leafid
  740. int parent_is_root = 0;
  741. int parent_is_parent = 0;
  742. if(likely(parent)) {
  743. parent_is_parent = !strcmp(parent, "parent");
  744. if(!parent_is_parent)
  745. parent_is_root = !strcmp(parent, "root");
  746. }
  747. if(likely(type && id && (parent_is_root || parent_is_parent))) {
  748. char qdisc = 0;
  749. if(first_hash == QDISC_HASH) {
  750. qdisc = 1;
  751. if(!strcmp(type, "ingress")) {
  752. // we don't want to get the ingress qdisc
  753. // there should be an IFB interface for this
  754. class = NULL;
  755. continue;
  756. }
  757. if(parent_is_parent && parentid) {
  758. // eliminate the minor number from parentid
  759. // why: parentid is the id of the parent class
  760. // but major: is also the id of the parent qdisc
  761. char *s = parentid;
  762. while(*s && *s != ':') s++;
  763. if(*s == ':') s[1] = '\0';
  764. }
  765. }
  766. if(parent_is_root) {
  767. parentid = NULL;
  768. leafid = NULL;
  769. }
  770. else if(!leaf || strcmp(leaf, "leaf") != 0)
  771. leafid = NULL;
  772. char leafbuf[20 + 1] = "";
  773. if(leafid && leafid[strlen(leafid) - 1] == ':') {
  774. strncpyz(leafbuf, leafid, 20 - 1);
  775. strcat(leafbuf, "1");
  776. leafid = leafbuf;
  777. }
  778. class = tc_class_add(device, id, qdisc, parentid, leafid);
  779. }
  780. else {
  781. // clear the last class
  782. class = NULL;
  783. }
  784. }
  785. else if(unlikely(first_hash == END_HASH && strcmp(words[0], "END") == 0)) {
  786. // debug(D_TC_LOOP, "END line");
  787. if(likely(device)) {
  788. netdata_thread_disable_cancelability();
  789. tc_device_commit(device);
  790. // tc_device_free(device);
  791. netdata_thread_enable_cancelability();
  792. }
  793. device = NULL;
  794. class = NULL;
  795. }
  796. else if(unlikely(first_hash == BEGIN_HASH && strcmp(words[0], "BEGIN") == 0)) {
  797. // debug(D_TC_LOOP, "BEGIN line on device '%s'", words[1]);
  798. if(likely(words[1] && *words[1])) {
  799. device = tc_device_create(words[1]);
  800. }
  801. else {
  802. // tc_device_free(device);
  803. device = NULL;
  804. }
  805. class = NULL;
  806. }
  807. else if(unlikely(device && class && first_hash == SENT_HASH && strcmp(words[0], "Sent") == 0)) {
  808. // debug(D_TC_LOOP, "SENT line '%s'", words[1]);
  809. if(likely(words[1] && *words[1])) {
  810. class->bytes = str2ull(words[1]);
  811. class->updated = 1;
  812. }
  813. else {
  814. class->updated = 0;
  815. }
  816. if(likely(words[3] && *words[3]))
  817. class->packets = str2ull(words[3]);
  818. if(likely(words[6] && *words[6]))
  819. class->dropped = str2ull(words[6]);
  820. if(likely(words[8] && *words[8]))
  821. class->overlimits = str2ull(words[8]);
  822. if(likely(words[10] && *words[10]))
  823. class->requeues = str2ull(words[8]);
  824. }
  825. else if(unlikely(device && class && class->updated && first_hash == LENDED_HASH && strcmp(words[0], "lended:") == 0)) {
  826. // debug(D_TC_LOOP, "LENDED line '%s'", words[1]);
  827. if(likely(words[1] && *words[1]))
  828. class->lended = str2ull(words[1]);
  829. if(likely(words[3] && *words[3]))
  830. class->borrowed = str2ull(words[3]);
  831. if(likely(words[5] && *words[5]))
  832. class->giants = str2ull(words[5]);
  833. }
  834. else if(unlikely(device && class && class->updated && first_hash == TOKENS_HASH && strcmp(words[0], "tokens:") == 0)) {
  835. // debug(D_TC_LOOP, "TOKENS line '%s'", words[1]);
  836. if(likely(words[1] && *words[1]))
  837. class->tokens = str2ull(words[1]);
  838. if(likely(words[3] && *words[3]))
  839. class->ctokens = str2ull(words[3]);
  840. }
  841. else if(unlikely(device && first_hash == SETDEVICENAME_HASH && strcmp(words[0], "SETDEVICENAME") == 0)) {
  842. // debug(D_TC_LOOP, "SETDEVICENAME line '%s'", words[1]);
  843. if(likely(words[1] && *words[1]))
  844. tc_device_set_device_name(device, words[1]);
  845. }
  846. else if(unlikely(device && first_hash == SETDEVICEGROUP_HASH && strcmp(words[0], "SETDEVICEGROUP") == 0)) {
  847. // debug(D_TC_LOOP, "SETDEVICEGROUP line '%s'", words[1]);
  848. if(likely(words[1] && *words[1]))
  849. tc_device_set_device_family(device, words[1]);
  850. }
  851. else if(unlikely(device && first_hash == SETCLASSNAME_HASH && strcmp(words[0], "SETCLASSNAME") == 0)) {
  852. // debug(D_TC_LOOP, "SETCLASSNAME line '%s' '%s'", words[1], words[2]);
  853. char *id = words[1];
  854. char *path = words[2];
  855. if(likely(id && *id && path && *path))
  856. tc_device_set_class_name(device, id, path);
  857. }
  858. else if(unlikely(first_hash == WORKTIME_HASH && strcmp(words[0], "WORKTIME") == 0)) {
  859. // debug(D_TC_LOOP, "WORKTIME line '%s' '%s'", words[1], words[2]);
  860. getrusage(RUSAGE_THREAD, &thread);
  861. static RRDSET *stcpu = NULL;
  862. static RRDDIM *rd_user = NULL, *rd_system = NULL;
  863. if(unlikely(!stcpu)) {
  864. stcpu = rrdset_create_localhost(
  865. "netdata"
  866. , "plugin_tc_cpu"
  867. , NULL
  868. , "tc.helper"
  869. , NULL
  870. , "Netdata TC CPU usage"
  871. , "milliseconds/s"
  872. , PLUGIN_TC_NAME
  873. , NULL
  874. , NETDATA_CHART_PRIO_NETDATA_TC_CPU
  875. , localhost->rrd_update_every
  876. , RRDSET_TYPE_STACKED
  877. );
  878. rd_user = rrddim_add(stcpu, "user", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL);
  879. rd_system = rrddim_add(stcpu, "system", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL);
  880. }
  881. else rrdset_next(stcpu);
  882. rrddim_set_by_pointer(stcpu, rd_user , thread.ru_utime.tv_sec * 1000000ULL + thread.ru_utime.tv_usec);
  883. rrddim_set_by_pointer(stcpu, rd_system, thread.ru_stime.tv_sec * 1000000ULL + thread.ru_stime.tv_usec);
  884. rrdset_done(stcpu);
  885. static RRDSET *sttime = NULL;
  886. static RRDDIM *rd_run_time = NULL;
  887. if(unlikely(!sttime)) {
  888. sttime = rrdset_create_localhost(
  889. "netdata"
  890. , "plugin_tc_time"
  891. , NULL
  892. , "tc.helper"
  893. , NULL
  894. , "Netdata TC script execution"
  895. , "milliseconds/run"
  896. , PLUGIN_TC_NAME
  897. , NULL
  898. , NETDATA_CHART_PRIO_NETDATA_TC_TIME
  899. , localhost->rrd_update_every
  900. , RRDSET_TYPE_AREA
  901. );
  902. rd_run_time = rrddim_add(sttime, "run_time", "run time", 1, 1, RRD_ALGORITHM_ABSOLUTE);
  903. }
  904. else rrdset_next(sttime);
  905. rrddim_set_by_pointer(sttime, rd_run_time, str2ll(words[1], NULL));
  906. rrdset_done(sttime);
  907. }
  908. //else {
  909. // debug(D_TC_LOOP, "IGNORED line");
  910. //}
  911. }
  912. // fgets() failed or loop broke
  913. int code = mypclose(fp, (pid_t)tc_child_pid);
  914. tc_child_pid = 0;
  915. if(unlikely(device)) {
  916. // tc_device_free(device);
  917. device = NULL;
  918. class = NULL;
  919. }
  920. if(unlikely(netdata_exit)) {
  921. tc_device_free_all();
  922. goto cleanup;
  923. }
  924. if(code == 1 || code == 127) {
  925. // 1 = DISABLE
  926. // 127 = cannot even run it
  927. error("TC: tc-qos-helper.sh exited with code %d. Disabling it.", code);
  928. tc_device_free_all();
  929. goto cleanup;
  930. }
  931. sleep((unsigned int) localhost->rrd_update_every);
  932. }
  933. cleanup: ; // added semi-colon to prevent older gcc error: label at end of compound statement
  934. netdata_thread_cleanup_pop(1);
  935. return NULL;
  936. }