char name_updated;
char updated; // updated bytes
- int seen; // seen in the tc list (even without bytes)
+ int unupdated; // the number of times, this has been found un-updated
struct tc_class *next;
struct tc_class *prev;
static int tc_device_compare(void* a, void* b) {
if(((struct tc_device *)a)->hash < ((struct tc_device *)b)->hash) return -1;
else if(((struct tc_device *)a)->hash > ((struct tc_device *)b)->hash) return 1;
- else return strsame(((struct tc_device *)a)->id, ((struct tc_device *)b)->id);
+ else return strcmp(((struct tc_device *)a)->id, ((struct tc_device *)b)->id);
}
avl_tree tc_device_root_index = {
static int tc_class_compare(void* a, void* b) {
if(((struct tc_class *)a)->hash < ((struct tc_class *)b)->hash) return -1;
else if(((struct tc_class *)a)->hash > ((struct tc_class *)b)->hash) return 1;
- else return strsame(((struct tc_class *)a)->id, ((struct tc_class *)b)->id);
+ else return strcmp(((struct tc_class *)a)->id, ((struct tc_class *)b)->id);
}
#define tc_class_index_add(st, rd) (struct tc_class *)avl_insert(&((st)->classes_index), (avl *)(rd))
if(c->next) c->next->prev = c->prev;
if(c->prev) c->prev->next = c->next;
- 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);
+ 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);
if(unlikely(tc_class_index_del(n, c) != c))
error("plugin_tc: INTERNAL ERROR: attempt remove class '%s' from device '%s': removed a different calls", c->id, n->id);
static int cleanup_every = 999;
if(unlikely(cleanup_every > 0)) {
- cleanup_every = (int) config_get_number("plugin:tc", "cleanup unused classes every", 60);
+ cleanup_every = (int) config_get_number("plugin:tc", "cleanup unused classes every", 120);
if(cleanup_every < 0) cleanup_every = -cleanup_every;
}
struct tc_class *c = d->classes;
while(c) {
- if(unlikely(cleanup_every > 0 && c->seen >= cleanup_every)) {
+ if(unlikely(cleanup_every && c->unupdated >= cleanup_every)) {
struct tc_class *nc = c->next;
tc_class_free(d, c);
c = nc;
for(c = d->classes ; c ; c = c->next) {
c->isleaf = 1;
c->hasparent = 0;
+
+ if(unlikely(!c->updated))
+ c->unupdated++;
+ else
+ c->unupdated = 0;
}
// mark the classes as leafs and parents
if(unlikely(c == x)) continue;
if(x->parentid && (
- ( c->hash == x->parent_hash && strsame(c->id, x->parentid) == 0) ||
- (c->leafid && c->leaf_hash == x->parent_hash && strsame(c->leafid, x->parentid) == 0))) {
+ ( 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', 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);
c->isleaf = 0;
x->hasparent = 1;
if(unlikely(d->enabled == (char)-1)) {
char var_name[CONFIG_MAX_NAME + 1];
snprintfz(var_name, CONFIG_MAX_NAME, "qos for %s", d->id);
- d->enabled = config_get_boolean_ondemand("plugin:tc", var_name, enable_new_interfaces);
+ d->enabled = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_new_interfaces);
snprintfz(var_name, CONFIG_MAX_NAME, "traffic chart for %s", d->id);
- d->enabled_bytes = config_get_boolean_ondemand("plugin:tc", var_name, enable_bytes);
+ d->enabled_bytes = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_bytes);
snprintfz(var_name, CONFIG_MAX_NAME, "packets chart for %s", d->id);
- d->enabled_packets = config_get_boolean_ondemand("plugin:tc", var_name, enable_packets);
+ d->enabled_packets = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_packets);
snprintfz(var_name, CONFIG_MAX_NAME, "dropped packets chart for %s", d->id);
- d->enabled_dropped = config_get_boolean_ondemand("plugin:tc", var_name, enable_dropped);
+ d->enabled_dropped = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_dropped);
snprintfz(var_name, CONFIG_MAX_NAME, "tokens chart for %s", d->id);
- d->enabled_tokens = config_get_boolean_ondemand("plugin:tc", var_name, enable_tokens);
+ d->enabled_tokens = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_tokens);
snprintfz(var_name, CONFIG_MAX_NAME, "ctokens chart for %s", d->id);
- d->enabled_ctokens = config_get_boolean_ondemand("plugin:tc", var_name, enable_ctokens);
+ d->enabled_ctokens = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_ctokens);
}
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), classes = %d (bytes = %llu, packets = %llu, dropped = %llu, tokens = %llu, ctokens = %llu).",
debug(D_TC_LOOP, "TC: Updating chart for device '%s'", d->name?d->name:d->id);
rrdset_next(d->st_bytes);
- if(unlikely(d->name_updated && d->name && strsame(d->id, d->name) != 0)) {
+ if(unlikely(d->name_updated && d->name && strcmp(d->id, d->name) != 0)) {
rrdset_set_name(d->st_bytes, d->name);
d->name_updated = 0;
}
if(unlikely(!c->updated)) continue;
if(c->isleaf && c->hasparent) {
- c->seen++;
-
if(unlikely(!c->rd_bytes)) {
c->rd_bytes = rrddim_find(d->st_bytes, c->id);
if(unlikely(!c->rd_bytes)) {
rrddim_set_by_pointer(d->st_bytes, c->rd_bytes, c->bytes);
// if it has a name, different to the id
- if(unlikely(c->name_updated && c->name && strsame(c->id, c->name) != 0)) {
+ if(unlikely(c->name_updated && c->name && strcmp(c->id, c->name) != 0)) {
// update the rrd dimension with the new name
debug(D_TC_LOOP, "TC: Setting chart '%s', dimension '%s' name to '%s'", d->st_bytes->id, c->rd_bytes->id, c->name);
rrddim_set_name(d->st_bytes, c->rd_bytes, c->name);
rrddim_set_by_pointer(d->st_packets, c->rd_packets, c->packets);
// if it has a name, different to the id
- if(unlikely(c->name_updated && c->name && strsame(c->id, c->name) != 0)) {
+ if(unlikely(c->name_updated && c->name && strcmp(c->id, c->name) != 0)) {
// update the rrd dimension with the new name
debug(D_TC_LOOP, "TC: Setting chart '%s', dimension '%s' name to '%s'", d->st_packets->id, c->rd_packets->id, c->name);
rrddim_set_name(d->st_packets, c->rd_packets, c->name);
rrddim_set_by_pointer(d->st_dropped, c->rd_dropped, c->dropped);
// if it has a name, different to the id
- if(unlikely(c->name_updated && c->name && strsame(c->id, c->name) != 0)) {
+ if(unlikely(c->name_updated && c->name && strcmp(c->id, c->name) != 0)) {
// update the rrd dimension with the new name
debug(D_TC_LOOP, "TC: Setting chart '%s', dimension '%s' name to '%s'", d->st_dropped->id, c->rd_dropped->id, c->name);
rrddim_set_name(d->st_dropped, c->rd_dropped, c->name);
rrddim_set_by_pointer(d->st_tokens, c->rd_tokens, c->tokens);
// if it has a name, different to the id
- if(unlikely(c->name_updated && c->name && strsame(c->id, c->name) != 0)) {
+ if(unlikely(c->name_updated && c->name && strcmp(c->id, c->name) != 0)) {
// update the rrd dimension with the new name
debug(D_TC_LOOP, "TC: Setting chart '%s', dimension '%s' name to '%s'", d->st_tokens->id, c->rd_tokens->id, c->name);
rrddim_set_name(d->st_tokens, c->rd_tokens, c->name);
rrddim_set_by_pointer(d->st_ctokens, c->rd_ctokens, c->ctokens);
// if it has a name, different to the id
- if(unlikely(c->name_updated && c->name && strsame(c->id, c->name) != 0)) {
+ if(unlikely(c->name_updated && c->name && strcmp(c->id, c->name) != 0)) {
// update the rrd dimension with the new name
debug(D_TC_LOOP, "TC: Setting chart '%s', dimension '%s' name to '%s'", d->st_ctokens->id, c->rd_ctokens->id, c->name);
rrddim_set_name(d->st_ctokens, c->rd_ctokens, c->name);
freez(c->name);
c->name = NULL;
- if(likely(name && *name && strsame(c->id, name) != 0)) {
+ if(likely(name && *name && strcmp(c->id, name) != 0)) {
debug(D_TC_LOOP, "TC: Setting device '%s', class '%s' name to '%s'", d->id, id, name);
c->name = strdupz(name);
c->name_updated = 1;
freez(d->name);
d->name = NULL;
- if(likely(name && *name && strsame(d->id, name) != 0)) {
+ if(likely(name && *name && strcmp(d->id, name) != 0)) {
debug(D_TC_LOOP, "TC: Setting device '%s' name to '%s'", d->id, name);
d->name = strdupz(name);
d->name_updated = 1;
freez(d->family);
d->family = NULL;
- if(likely(family && *family && strsame(d->id, family) != 0)) {
+ if(likely(family && *family && strcmp(d->id, family) != 0)) {
debug(D_TC_LOOP, "TC: Setting device '%s' family to '%s'", d->id, family);
d->family = strdupz(family);
d->family_updated = 1;
if(unlikely(tc_class_index_add(n, c) != c))
error("plugin_tc: INTERNAL ERROR: attempt index class '%s' on device '%s': already exists", c->id, n->id);
}
-
- c->seen = 1;
-
return(c);
}
first_hash = simple_hash(words[0]);
- if(unlikely(device && first_hash == CLASS_HASH && strsame(words[0], "class") == 0)) {
+ if(unlikely(device && first_hash == CLASS_HASH && strcmp(words[0], "class") == 0)) {
// 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]);
// words[1] : class type
// words[2] : N:XX
// words[3] : parent or root
- if(likely(words[1] && words[2] && words[3] && (strsame(words[3], "parent") == 0 || strsame(words[3], "root") == 0))) {
+ if(likely(words[1] && words[2] && words[3] && (strcmp(words[3], "parent") == 0 || strcmp(words[3], "root") == 0))) {
//char *type = words[1]; // the class: htb, fq_codel, etc
// we are only interested for HTB classes
- //if(strsame(type, "htb") != 0) continue;
+ //if(strcmp(type, "htb") != 0) continue;
char *id = words[2]; // the class major:minor
char *parent = words[3]; // 'parent' or 'root'
char *leaf = words[5]; // 'leaf'
char *leafid = words[6]; // leafid
- if(strsame(parent, "root") == 0) {
+ if(strcmp(parent, "root") == 0) {
parentid = NULL;
leafid = NULL;
}
- else if(!leaf || strsame(leaf, "leaf") != 0)
+ else if(!leaf || strcmp(leaf, "leaf") != 0)
leafid = NULL;
char leafbuf[20 + 1] = "";
class = NULL;
}
}
- else if(unlikely(first_hash == END_HASH && strsame(words[0], "END") == 0)) {
+ else if(unlikely(first_hash == END_HASH && strcmp(words[0], "END") == 0)) {
// debug(D_TC_LOOP, "END line");
if(likely(device)) {
device = NULL;
class = NULL;
}
- else if(unlikely(first_hash == BEGIN_HASH && strsame(words[0], "BEGIN") == 0)) {
+ else if(unlikely(first_hash == BEGIN_HASH && strcmp(words[0], "BEGIN") == 0)) {
// debug(D_TC_LOOP, "BEGIN line on device '%s'", words[1]);
if(likely(words[1] && *words[1])) {
class = NULL;
}
- else if(unlikely(device && class && first_hash == SENT_HASH && strsame(words[0], "Sent") == 0)) {
+ else if(unlikely(device && class && first_hash == SENT_HASH && strcmp(words[0], "Sent") == 0)) {
// debug(D_TC_LOOP, "SENT line '%s'", words[1]);
if(likely(words[1] && *words[1])) {
class->bytes = str2ull(words[1]);
if(likely(words[10] && *words[10]))
class->requeues = str2ull(words[8]);
}
- else if(unlikely(device && class && class->updated && first_hash == LENDED_HASH && strsame(words[0], "lended:") == 0)) {
+ else if(unlikely(device && class && class->updated && first_hash == LENDED_HASH && strcmp(words[0], "lended:") == 0)) {
// debug(D_TC_LOOP, "LENDED line '%s'", words[1]);
if(likely(words[1] && *words[1]))
class->lended = str2ull(words[1]);
if(likely(words[5] && *words[5]))
class->giants = str2ull(words[5]);
}
- else if(unlikely(device && class && class->updated && first_hash == TOKENS_HASH && strsame(words[0], "tokens:") == 0)) {
+ else if(unlikely(device && class && class->updated && first_hash == TOKENS_HASH && strcmp(words[0], "tokens:") == 0)) {
// debug(D_TC_LOOP, "TOKENS line '%s'", words[1]);
if(likely(words[1] && *words[1]))
class->tokens = str2ull(words[1]);
if(likely(words[3] && *words[3]))
class->ctokens = str2ull(words[3]);
}
- else if(unlikely(device && first_hash == SETDEVICENAME_HASH && strsame(words[0], "SETDEVICENAME") == 0)) {
+ else if(unlikely(device && first_hash == SETDEVICENAME_HASH && strcmp(words[0], "SETDEVICENAME") == 0)) {
// debug(D_TC_LOOP, "SETDEVICENAME line '%s'", words[1]);
if(likely(words[1] && *words[1]))
tc_device_set_device_name(device, words[1]);
}
- else if(unlikely(device && first_hash == SETDEVICEGROUP_HASH && strsame(words[0], "SETDEVICEGROUP") == 0)) {
+ else if(unlikely(device && first_hash == SETDEVICEGROUP_HASH && strcmp(words[0], "SETDEVICEGROUP") == 0)) {
// debug(D_TC_LOOP, "SETDEVICEGROUP line '%s'", words[1]);
if(likely(words[1] && *words[1]))
tc_device_set_device_family(device, words[1]);
}
- else if(unlikely(device && first_hash == SETCLASSNAME_HASH && strsame(words[0], "SETCLASSNAME") == 0)) {
+ else if(unlikely(device && first_hash == SETCLASSNAME_HASH && strcmp(words[0], "SETCLASSNAME") == 0)) {
// debug(D_TC_LOOP, "SETCLASSNAME line '%s' '%s'", words[1], words[2]);
char *id = words[1];
char *path = words[2];
if(likely(id && *id && path && *path))
tc_device_set_class_name(device, id, path);
}
- else if(unlikely(first_hash == WORKTIME_HASH && strsame(words[0], "WORKTIME") == 0)) {
+ else if(unlikely(first_hash == WORKTIME_HASH && strcmp(words[0], "WORKTIME") == 0)) {
// debug(D_TC_LOOP, "WORKTIME line '%s' '%s'", words[1], words[2]);
getrusage(RUSAGE_THREAD, &thread);
}
#ifdef DETACH_PLUGINS_FROM_NETDATA
- else if(unlikely(first_hash == MYPID_HASH && (strsame(words[0], "MYPID") == 0))) {
+ else if(unlikely(first_hash == MYPID_HASH && (strcmp(words[0], "MYPID") == 0))) {
// debug(D_TC_LOOP, "MYPID line '%s'", words[1]);
char *id = words[1];
pid_t pid = atol(id);