attempt to handle division by zero
Costa Tsaousis (ktsaou) committed
May 10, 2014 at 05:37 UTC
65fd6f6669ebf5911f02ffb982688ec8daed5c29
1 file changed
+6
-1
netdata.c
+6
-1
@@ -1122,6 +1122,7 @@ RRD_DIMENSION *rrd_stats_dimension_add(RRD_STATS *st, const char *id, const char
1122
1123
snprintf(varname, CONFIG_MAX_NAME, "dim %s divisor", rd->id);
1124
rd->divisor = config_get_number(st->id, varname, divisor);
1125
+ if(!rd->divisor) rd->divisor = 1;
1126
1127
rd->entries = st->entries;
1128
@@ -1328,6 +1329,7 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
1329
if(st->counter) {
1330
1331
st->usec_since_last_update = usecdiff(&now, &st->last_updated);
1332
+ if(!st->usec_since_last_update) st->usec_since_last_update = 1;
1333
if(st->debug) debug(D_RRD_STATS, "microseconds since last update: %llu", st->usec_since_last_update);
1334
1335
// x 10
@@ -1340,7 +1342,8 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
1342
case RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL:
1343
// the percentage of the current increment
1344
// over the increment of all dimensions together
1343
- rd->calculated_value =
1345
+ if(st->absolute_total == st->last_absolute_total) rd->calculated_value = 0;
1346
+ else rd->calculated_value =
1347
(calculated_number)10
1348
* (calculated_number)100
1349
* (calculated_number)(rd->collected_value - rd->last_collected_value)
@@ -1359,6 +1362,8 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
1362
break;
1363
1364
case RRD_DIMENSION_PCENT_OVER_ROW_TOTAL:
1365
+ if(!st->absolute_total) rd->calculated_value = 0;
1366
+ else
1367
// the percentage of the current value
1368
// over the total of all dimensions
1369
rd->calculated_value =