fix for dynamic add, removing and renaming tc classes
Costa Tsaousis (ktsaou) committed
Mar 31, 2014 at 01:11 UTC
990ec25bb5e95cb0c3224b32585773c24b110bb7
1 file changed
+18
-4
netdata.c
+18
-4
@@ -566,7 +566,7 @@ void rrd_stats_done(RRD_STATS *st)
566
567
// find if there are any obsolete dimensions (not updated recently)
568
for( rd = st->dimensions, last = NULL ; rd ; ) {
569
- if(rd->last_updated < st->last_updated) {
569
+ if((rd->last_updated + (10 * update_every)) < st->last_updated) { // remove it only it is not updated in 10 seconds
570
debug(D_RRD_STATS, "Removing obsolete dimension '%s' (%s) of '%s' (%s).", rd->name, rd->id, st->name, st->id);
571
572
if(!last) {
@@ -592,12 +592,12 @@ void rrd_stats_done(RRD_STATS *st)
592
pthread_mutex_unlock(&st->mutex);
593
}
594
595
-void rrd_stats_dimension_set(RRD_STATS *st, const char *id, void *data)
595
+int rrd_stats_dimension_set(RRD_STATS *st, const char *id, void *data)
596
{
597
RRD_DIMENSION *rd = rrd_stats_dimension_find(st, id);
598
if(!rd) {
599
error("Cannot find dimension with id '%s' on stats '%s' (%s).", id, st->name, st->id);
600
- return;
600
+ return 1;
601
}
602
603
rd->last_updated = st->last_updated;
@@ -623,6 +623,8 @@ void rrd_stats_dimension_set(RRD_STATS *st, const char *id, void *data)
623
dimension[st->current_entry] = (*value);
624
}
625
else fatal("I don't know how to handle data of length %d bytes.", rd->bytes);
626
+
627
+ return 0;
628
}
629
630
#define GROUP_AVERAGE 0
@@ -2532,7 +2534,19 @@ void tc_device_commit(struct tc_device *d)
2534
2535
for ( c = d->classes ; c ; c = c->next) {
2536
if(c->isleaf && c->hasparent)
2535
- rrd_stats_dimension_set(st, c->id, &c->bytes);
2537
+ if(rrd_stats_dimension_set(st, c->id, &c->bytes) != 0) {
2538
+
2539
+ // new class, we have to add it
2540
+ if(!rrd_stats_dimension_add(st, c->id, c->name, sizeof(unsigned long long), 8, 1024, RRD_DIMENSION_INCREMENTAL))
2541
+ error("Cannot add RRD_STATS dimension %s.", c->name);
2542
+ else rrd_stats_dimension_set(st, c->id, &c->bytes);
2543
+ }
2544
+
2545
+ // check if the class changed name
2546
+ RRD_DIMENSION *rd;
2547
+ for(rd = st->dimensions ; rd ; rd = rd->next) {
2548
+ if(strcmp(rd->id, c->id) == 0) { strcpy(rd->name, c->name); break; }
2549
+ }
2550
}
2551
rrd_stats_done(st);
2552
}