prevent interpolation on absolute values that are collected on time
Costa Tsaousis (ktsaou) committed
Dec 22, 2015 at 02:16 UTC
52aad6d81f0a0a8e14ac3de60a59cafc40d86faa
1 file changed
+35
-20
src/rrd.c
+35
-20
@@ -1048,7 +1048,7 @@ unsigned long long rrdset_done(RRDSET *st)
1048
int iterations = (now_ut - last_ut) / (st->update_every * 1000000ULL);
1049
1050
for( ; likely(next_ut <= now_ut) ; next_ut += st->update_every * 1000000ULL, iterations-- ) {
1051
- if(iterations < 0) error("iterations calculation wrapped!");
1051
+ if(iterations <= 0) error("iterations calculation wrapped!");
1052
1053
if(unlikely(st->debug)) {
1054
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)
1090
case RRDDIM_PCENT_OVER_ROW_TOTAL:
1091
case RRDDIM_PCENT_OVER_DIFF_TOTAL:
1092
default:
1093
- new_value = (calculated_number)
1094
- ( ( (rd->calculated_value - rd->last_calculated_value)
1095
- * (calculated_number)(next_ut - first_ut)
1096
- / (calculated_number)(now_ut - first_ut)
1097
- )
1098
- + rd->last_calculated_value
1099
- );
1093
+ if(iterations == 1) {
1094
+ // this is the last iteration
1095
+ // do not interpolate
1096
+ // just show the calculated value
1097
1101
- if(unlikely(st->debug))
1102
- debug(D_RRD_STATS, "%s/%s: CALC2 DEF "
1103
- CALCULATED_NUMBER_FORMAT " = ((("
1104
- "(" CALCULATED_NUMBER_FORMAT " - " CALCULATED_NUMBER_FORMAT ")"
1105
- " * %llu"
1106
- " / %llu) + " CALCULATED_NUMBER_FORMAT
1107
- , st->id, rd->name
1108
- , new_value
1109
- , rd->calculated_value, rd->last_calculated_value
1110
- , (next_ut - first_ut)
1111
- , (now_ut - first_ut), rd->last_calculated_value
1098
+ new_value = rd->calculated_value;
1099
+ }
1100
+ else {
1101
+ // we have missed an update
1102
+ // interpolate in the middle values
1103
+
1104
+ new_value = (calculated_number)
1105
+ ( ( (rd->calculated_value - rd->last_calculated_value)
1106
+ * (calculated_number)(next_ut - first_ut)
1107
+ / (calculated_number)(now_ut - first_ut)
1108
+ )
1109
+ + rd->last_calculated_value
1110
);
1111
1114
- if(likely(next_ut + st->update_every * 1000000ULL > now_ut)) rd->calculated_value = new_value;
1112
+ if(unlikely(st->debug))
1113
+ debug(D_RRD_STATS, "%s/%s: CALC2 DEF "
1114
+ CALCULATED_NUMBER_FORMAT " = ((("
1115
+ "(" CALCULATED_NUMBER_FORMAT " - " CALCULATED_NUMBER_FORMAT ")"
1116
+ " * %llu"
1117
+ " / %llu) + " CALCULATED_NUMBER_FORMAT
1118
+ , st->id, rd->name
1119
+ , new_value
1120
+ , rd->calculated_value, rd->last_calculated_value
1121
+ , (next_ut - first_ut)
1122
+ , (now_ut - first_ut), rd->last_calculated_value
1123
+ );
1124
+
1125
+ // this is wrong
1126
+ // it fades the value towards the target
1127
+ // while we know the calculated value is different
1128
+ // if(likely(next_ut + st->update_every * 1000000ULL > now_ut)) rd->calculated_value = new_value;
1129
+ }
1130
break;
1131
}
1132