]> arthur.barton.de Git - netdata.git/blobdiff - src/plugin_tc.c
multi-host rrdset and rrdfamily operations
[netdata.git] / src / plugin_tc.c
index 95a4d3dcadb29ec43cd5dc8080204ceefcf6dbd7..9ef7cead81db7dee7bccbf2cc5582476118b5f32 100644 (file)
@@ -230,17 +230,20 @@ static inline void tc_device_commit(struct tc_device *d) {
     int active_nodes = 0, updated_classes = 0, updated_qdiscs = 0;
 
     // prepare all classes
+    // we set reasonable defaults for the rest of the code below
+
     for(c = d->classes ; c ; c = c->next) {
-        c->render = 0;
+        c->render = 0;          // do not render this class
 
-        c->isleaf = 1;
-        c->hasparent = 0;
+        c->isleaf = 1;          // this is a leaf class
+        c->hasparent = 0;       // without a parent
 
         if(unlikely(!c->updated))
-            c->unupdated++;
+            c->unupdated++;     // increase its unupdated counter
         else {
-            c->unupdated = 0;
+            c->unupdated = 0;   // reset its unupdated counter
 
+            // count how many of each kind
             if(c->isqdisc)
                 updated_qdiscs++;
             else
@@ -256,6 +259,8 @@ static inline void tc_device_commit(struct tc_device *d) {
 
     if(unlikely(updated_classes && updated_qdiscs)) {
         error("TC: device '%s' has active both classes (%d) and qdiscs (%d). Will render only qdiscs.", d->id, updated_classes, updated_qdiscs);
+
+        // set all classes to !updated
         for(c = d->classes ; c ; c = c->next)
             if(unlikely(!c->isqdisc && c->updated))
                 c->updated = 0;
@@ -264,39 +269,49 @@ static inline void tc_device_commit(struct tc_device *d) {
     }
 
     // mark the classes as leafs and parents
-    for(c = d->classes; c; c = c->next) {
-        if(unlikely(!c->updated)) continue;
-
-        //debug(D_TC_LOOP, "TC: In device '%s', %s '%s'  has leafid: '%s' and parentid '%s'.",
-        //    d->id,
-        //    c->isqdisc?"qdisc":"class",
-        //    c->id,
-        //    c->leafid?c->leafid:"NULL",
-        //    c->parentid?c->parentid:"NULL");
-
-        // find if c is leaf or not
-        for(x = d->classes; x; x = x->next) {
-            if(unlikely(!x->updated || c == x || !x->parentid)) continue;
-
-            if( (c->hash == x->parent_hash && strcmp(c->id, x->parentid) == 0) ||
-                (c->leafid && c->leaf_hash == x->parent_hash && strcmp(c->leafid, x->parentid) == 0)) {
-                // 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);
-                c->isleaf = 0;
-                x->hasparent = 1;
+    //
+    // TC is hierarchical:
+    //  - classes can have other classes in them
+    //  - the same is true for qdiscs (i.e. qdiscs have classes, that have other qdiscs)
+    //
+    // we need to present a chart with leaf nodes only, so that the sum
+    // of all dimensions of the chart, will be the total utilization
+    // of the interface.
+    //
+    // here we try to find the ones we need to report
+    // by default all nodes are marked with: isleaf = 1 (see above)
+    //
+    // so, here we remove the isleaf flag from nodes in the middle
+    // and we add the hasparent flag to leaf nodes we found their parent
+    if(likely(!d->enabled_all_classes_qdiscs)) {
+        for(c = d->classes; c; c = c->next) {
+            if(unlikely(!c->updated)) continue;
+
+            //debug(D_TC_LOOP, "TC: In device '%s', %s '%s'  has leafid: '%s' and parentid '%s'.",
+            //    d->id,
+            //    c->isqdisc?"qdisc":"class",
+            //    c->id,
+            //    c->leafid?c->leafid:"NULL",
+            //    c->parentid?c->parentid:"NULL");
+
+            // find if c is leaf or not
+            for(x = d->classes; x; x = x->next) {
+                if(unlikely(!x->updated || c == x || !x->parentid)) continue;
+
+                // classes have both parentid and leafid
+                // qdiscs have only parentid
+                // the following works for both (it is an OR)
+
+                if((c->hash == x->parent_hash && strcmp(c->id, x->parentid) == 0) ||
+                   (c->leafid && c->leaf_hash == x->parent_hash && strcmp(c->leafid, x->parentid) == 0)) {
+                    // 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);
+                    c->isleaf = 0;
+                    x->hasparent = 1;
+                }
             }
         }
     }
 
-    // debugging only
-    /*
-    if(unlikely(debug_flags & D_TC_LOOP)) {
-        for(c = d->classes ; c ; c = c->next) {
-            if((c->isleaf && c->hasparent) || d->enabled_all_classes_qdiscs) debug(D_TC_LOOP, "TC: final nodes dump for '%s': class %s, OK", d->name, c->id);
-            else debug(D_TC_LOOP, "TC: final nodes dump for '%s': class %s, IGNORE (isleaf: %d, hasparent: %d, parent: %s)", d->name?d->name:d->id, c->id, c->isleaf, c->hasparent, c->parentid?c->parentid:"(unset)");
-        }
-    }
-    */
-
     for(c = d->classes ; c ; c = c->next) {
         if(unlikely(!c->updated)) continue;
 
@@ -319,6 +334,17 @@ static inline void tc_device_commit(struct tc_device *d) {
         //}
     }
 
+#ifdef NETDATA_INTERNAL_CHECKS
+    // dump all the list to see what we know
+
+    if(unlikely(debug_flags & D_TC_LOOP)) {
+        for(c = d->classes ; c ; c = c->next) {
+            if(c->render) debug(D_TC_LOOP, "TC: final nodes dump for '%s': class %s, OK", d->name, c->id);
+            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)");
+        }
+    }
+#endif
+
     if(unlikely(!active_nodes)) {
         debug(D_TC_LOOP, "TC: Ignoring TC device '%s'. No useful classes/qdiscs.", d->name?d->name:d->id);
         tc_device_classes_cleanup(d);
@@ -362,7 +388,7 @@ static inline void tc_device_commit(struct tc_device *d) {
             if(unlikely(!c->render)) continue;
 
             if(unlikely(!c->rd_bytes))
-                c->rd_bytes = rrddim_add(d->st_bytes, c->id, c->name?c->name:c->id, 8, 1024, RRDDIM_INCREMENTAL);
+                c->rd_bytes = rrddim_add(d->st_bytes, c->id, c->name?c->name:c->id, 8, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
             else if(unlikely(c->name_updated))
                 rrddim_set_name(d->st_bytes, c->rd_bytes, c->name);
 
@@ -402,7 +428,7 @@ static inline void tc_device_commit(struct tc_device *d) {
             if(unlikely(!c->render)) continue;
 
             if(unlikely(!c->rd_packets))
-                c->rd_packets = rrddim_add(d->st_packets, c->id, c->name?c->name:c->id, 1, 1, RRDDIM_INCREMENTAL);
+                c->rd_packets = rrddim_add(d->st_packets, c->id, c->name?c->name:c->id, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
             else if(unlikely(c->name_updated))
                 rrddim_set_name(d->st_packets, c->rd_packets, c->name);
 
@@ -442,7 +468,7 @@ static inline void tc_device_commit(struct tc_device *d) {
             if(unlikely(!c->render)) continue;
 
             if(unlikely(!c->rd_dropped))
-                c->rd_dropped = rrddim_add(d->st_dropped, c->id, c->name?c->name:c->id, 1, 1, RRDDIM_INCREMENTAL);
+                c->rd_dropped = rrddim_add(d->st_dropped, c->id, c->name?c->name:c->id, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
             else if(unlikely(c->name_updated))
                 rrddim_set_name(d->st_dropped, c->rd_dropped, c->name);
 
@@ -482,7 +508,7 @@ static inline void tc_device_commit(struct tc_device *d) {
             if(unlikely(!c->render)) continue;
 
             if(unlikely(!c->rd_tokens)) {
-                c->rd_tokens = rrddim_add(d->st_tokens, c->id, c->name?c->name:c->id, 1, 1, RRDDIM_ABSOLUTE);
+                c->rd_tokens = rrddim_add(d->st_tokens, c->id, c->name?c->name:c->id, 1, 1, RRDDIM_ALGORITHM_ABSOLUTE);
             }
             else if(unlikely(c->name_updated))
                 rrddim_set_name(d->st_tokens, c->rd_tokens, c->name);
@@ -524,7 +550,7 @@ static inline void tc_device_commit(struct tc_device *d) {
             if(unlikely(!c->render)) continue;
 
             if(unlikely(!c->rd_ctokens))
-                c->rd_ctokens = rrddim_add(d->st_ctokens, c->id, c->name?c->name:c->id, 1, 1, RRDDIM_ABSOLUTE);
+                c->rd_ctokens = rrddim_add(d->st_ctokens, c->id, c->name?c->name:c->id, 1, 1, RRDDIM_ALGORITHM_ABSOLUTE);
             else if(unlikely(c->name_updated))
                 rrddim_set_name(d->st_ctokens, c->rd_ctokens, c->name);
 
@@ -756,7 +782,7 @@ void *tc_main(void *ptr) {
 #endif
     uint32_t first_hash;
 
-    snprintfz(buffer, TC_LINE_MAX, "%s/tc-qos-helper.sh", config_get("plugins", "plugins directory", PLUGINS_DIR));
+    snprintfz(buffer, TC_LINE_MAX, "%s/tc-qos-helper.sh", netdata_configured_plugins_dir);
     char *tc_script = config_get("plugin:tc", "script to run to get tc values", buffer);
     
     for(;1;) {
@@ -826,6 +852,9 @@ void *tc_main(void *ptr) {
 
                         if(parent_is_parent && parentid) {
                             // eliminate the minor number from parentid
+                            // why: parentid is the id of the parent class
+                            // but major: is also the id of the parent qdisc
+
                             char *s = parentid;
                             while(*s && *s != ':') s++;
                             if(*s == ':') s[1] = '\0';
@@ -945,11 +974,11 @@ void *tc_main(void *ptr) {
                 // debug(D_TC_LOOP, "WORKTIME line '%s' '%s'", words[1], words[2]);
                 getrusage(RUSAGE_THREAD, &thread);
 
-                if(unlikely(!stcpu)) stcpu = rrdset_find("netdata.plugin_tc_cpu");
+                if(unlikely(!stcpu)) stcpu = rrdset_find_localhost("netdata.plugin_tc_cpu");
                 if(unlikely(!stcpu)) {
                     stcpu = rrdset_create("netdata", "plugin_tc_cpu", NULL, "tc.helper", NULL, "NetData TC CPU usage", "milliseconds/s", 135000, rrd_update_every, RRDSET_TYPE_STACKED);
-                    rrddim_add(stcpu, "user",  NULL,  1, 1000, RRDDIM_INCREMENTAL);
-                    rrddim_add(stcpu, "system", NULL, 1, 1000, RRDDIM_INCREMENTAL);
+                    rrddim_add(stcpu, "user",  NULL,  1, 1000, RRDDIM_ALGORITHM_INCREMENTAL);
+                    rrddim_add(stcpu, "system", NULL, 1, 1000, RRDDIM_ALGORITHM_INCREMENTAL);
                 }
                 else rrdset_next(stcpu);
 
@@ -957,10 +986,10 @@ void *tc_main(void *ptr) {
                 rrddim_set(stcpu, "system", thread.ru_stime.tv_sec * 1000000ULL + thread.ru_stime.tv_usec);
                 rrdset_done(stcpu);
 
-                if(unlikely(!sttime)) stcpu = rrdset_find("netdata.plugin_tc_time");
+                if(unlikely(!sttime)) stcpu = rrdset_find_localhost("netdata.plugin_tc_time");
                 if(unlikely(!sttime)) {
                     sttime = rrdset_create("netdata", "plugin_tc_time", NULL, "tc.helper", NULL, "NetData TC script execution", "milliseconds/run", 135001, rrd_update_every, RRDSET_TYPE_AREA);
-                    rrddim_add(sttime, "run_time",  "run time",  1, 1, RRDDIM_ABSOLUTE);
+                    rrddim_add(sttime, "run_time",  "run time",  1, 1, RRDDIM_ALGORITHM_ABSOLUTE);
                 }
                 else rrdset_next(sttime);