From 52aad6d81f0a0a8e14ac3de60a59cafc40d86faa Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Tue, 22 Dec 2015 02:16:28 +0200 Subject: [PATCH] prevent interpolation on absolute values that are collected on time --- src/rrd.c | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/src/rrd.c b/src/rrd.c index 9604337d..ac96ea6d 100755 --- a/src/rrd.c +++ b/src/rrd.c @@ -1048,7 +1048,7 @@ unsigned long long rrdset_done(RRDSET *st) int iterations = (now_ut - last_ut) / (st->update_every * 1000000ULL); for( ; likely(next_ut <= now_ut) ; next_ut += st->update_every * 1000000ULL, iterations-- ) { - if(iterations < 0) error("iterations calculation wrapped!"); + if(iterations <= 0) error("iterations calculation wrapped!"); if(unlikely(st->debug)) { debug(D_RRD_STATS, "%s: last ut = %0.3Lf (last updated time)", st->name, (long double)last_ut/1000000.0); @@ -1090,28 +1090,43 @@ unsigned long long rrdset_done(RRDSET *st) case RRDDIM_PCENT_OVER_ROW_TOTAL: case RRDDIM_PCENT_OVER_DIFF_TOTAL: default: - new_value = (calculated_number) - ( ( (rd->calculated_value - rd->last_calculated_value) - * (calculated_number)(next_ut - first_ut) - / (calculated_number)(now_ut - first_ut) - ) - + rd->last_calculated_value - ); + if(iterations == 1) { + // this is the last iteration + // do not interpolate + // just show the calculated value - if(unlikely(st->debug)) - debug(D_RRD_STATS, "%s/%s: CALC2 DEF " - CALCULATED_NUMBER_FORMAT " = (((" - "(" CALCULATED_NUMBER_FORMAT " - " CALCULATED_NUMBER_FORMAT ")" - " * %llu" - " / %llu) + " CALCULATED_NUMBER_FORMAT - , st->id, rd->name - , new_value - , rd->calculated_value, rd->last_calculated_value - , (next_ut - first_ut) - , (now_ut - first_ut), rd->last_calculated_value + new_value = rd->calculated_value; + } + else { + // we have missed an update + // interpolate in the middle values + + new_value = (calculated_number) + ( ( (rd->calculated_value - rd->last_calculated_value) + * (calculated_number)(next_ut - first_ut) + / (calculated_number)(now_ut - first_ut) + ) + + rd->last_calculated_value ); - if(likely(next_ut + st->update_every * 1000000ULL > now_ut)) rd->calculated_value = new_value; + if(unlikely(st->debug)) + debug(D_RRD_STATS, "%s/%s: CALC2 DEF " + CALCULATED_NUMBER_FORMAT " = (((" + "(" CALCULATED_NUMBER_FORMAT " - " CALCULATED_NUMBER_FORMAT ")" + " * %llu" + " / %llu) + " CALCULATED_NUMBER_FORMAT + , st->id, rd->name + , new_value + , rd->calculated_value, rd->last_calculated_value + , (next_ut - first_ut) + , (now_ut - first_ut), rd->last_calculated_value + ); + + // this is wrong + // it fades the value towards the target + // while we know the calculated value is different + // if(likely(next_ut + st->update_every * 1000000ULL > now_ut)) rd->calculated_value = new_value; + } break; } -- 2.39.2