@cryptotaxi247 / netdata-1 / commits / 7a97ac697

statsd timers and histograms should report zeros if nothing is collected

Costa Tsaousis (ktsaou) committed Dec 5, 2017 at 12:13 UTC 7a97ac69743e92cc3c05f3ac6d5f2d3f002edde0
1 file changed +20 -2
src/statsd.c
+20 -2
@@ -54,6 +54,8 @@ typedef struct statsd_histogram_extensions {
54 collected_number last_stddev;
55 collected_number last_sum;
56
57 + int zeroed;
58 +
59 RRDDIM *rd_min;
60 RRDDIM *rd_max;
61 RRDDIM *rd_percentile;
@@ -482,7 +484,7 @@ static inline void statsd_process_histogram(STATSD_METRIC *m, const char *value,
484
485 static inline void statsd_process_timer(STATSD_METRIC *m, const char *value, const char *sampling) {
486 if(unlikely(!value || !*value)) {
485 - error("STATSD: metric of type set, with empty value is ignored.");
487 + error("STATSD: metric of type timer, with empty value is ignored.");
488 return;
489 }
490
@@ -1489,6 +1491,22 @@ static inline void statsd_flush_timer_or_histogram(STATSD_METRIC *m, const char
1491
1492 netdata_mutex_lock(&m->histogram.ext->mutex);
1493
1494 + if(unlikely(!m->histogram.ext->zeroed)) {
1495 + // reset the metrics
1496 + // if we collected anything, they will be updated below
1497 + // this ensures that we report zeros if nothing is collected
1498 +
1499 + m->histogram.ext->last_min = 0;
1500 + m->histogram.ext->last_max = 0;
1501 + m->last = 0;
1502 + m->histogram.ext->last_median = 0;
1503 + m->histogram.ext->last_stddev = 0;
1504 + m->histogram.ext->last_sum = 0;
1505 + m->histogram.ext->last_percentile = 0;
1506 +
1507 + m->histogram.ext->zeroed = 1;
1508 + }
1509 +
1510 int updated = 0;
1511 if(m->count && !m->reset && m->histogram.ext->used > 0) {
1512 size_t len = m->histogram.ext->used;
@@ -1511,11 +1529,11 @@ static inline void statsd_flush_timer_or_histogram(STATSD_METRIC *m, const char
1529 debug(D_STATSD, "STATSD %s metric %s: min " COLLECTED_NUMBER_FORMAT ", max " COLLECTED_NUMBER_FORMAT ", last " COLLECTED_NUMBER_FORMAT ", pcent " COLLECTED_NUMBER_FORMAT ", median " COLLECTED_NUMBER_FORMAT ", stddev " COLLECTED_NUMBER_FORMAT ", sum " COLLECTED_NUMBER_FORMAT,
1530 dim, m->name, m->histogram.ext->last_min, m->histogram.ext->last_max, m->last, m->histogram.ext->last_percentile, m->histogram.ext->last_median, m->histogram.ext->last_stddev, m->histogram.ext->last_sum);
1531
1532 + m->histogram.ext->zeroed = 0;
1533 m->reset = 1;
1534 updated = 1;
1535 }
1536
1518 -
1537 if(m->options & STATSD_METRIC_OPTION_PRIVATE_CHART_ENABLED && (updated || !(m->options & STATSD_METRIC_OPTION_SHOW_GAPS_WHEN_NOT_COLLECTED)))
1538 statsd_private_chart_timer_or_histogram(m, dim, family, units);
1539