@cryptotaxi247 / netdata-1 / commits / 3a4cfc79c

statsd: fix incorrect calculation of 95th percentile; allow synthetic charts to have fixed colors on the dashboard by adding the dimensions with the same order they appear on the configuration file

Costa Tsaousis (ktsaou) committed May 17, 2017 at 02:24 UTC 3a4cfc79c8f4206134637ef867b9481efda7c81d
1 file changed +23 -8
src/statsd.c
+23 -8
@@ -1083,9 +1083,6 @@ int statsd_readfile(const char *path, const char *filename) {
1083 char *divider = words[4];
1084
1085 STATSD_APP_CHART_DIM *dim = callocz(sizeof(STATSD_APP_CHART_DIM), 1);
1086 - dim->next = chart->dimensions;
1087 - chart->dimensions = dim;
1088 - chart->dimensions_count++;
1086
1087 dim->metric = strdupz(metric_name);
1088 dim->metric_hash = simple_hash(dim->metric);
@@ -1118,6 +1115,19 @@ int statsd_readfile(const char *path, const char *filename) {
1115 dim->divider = 1;
1116 }
1117
1118 + // append it to the list of dimension
1119 + STATSD_APP_CHART_DIM *tdim;
1120 + for(tdim = chart->dimensions; tdim && tdim->next ; tdim = tdim->next) ;
1121 + if(!tdim) {
1122 + dim->next = chart->dimensions;
1123 + chart->dimensions = dim;
1124 + }
1125 + else {
1126 + dim->next = tdim->next;
1127 + tdim->next = dim;
1128 + }
1129 + chart->dimensions_count++;
1130 +
1131 debug(D_STATSD, "Added dimension '%s' to chart '%s' of app '%s', for metric '%s', with type %u, multiplier " COLLECTED_NUMBER_FORMAT ", divider " COLLECTED_NUMBER_FORMAT,
1132 dim->name, chart->name, app->name, dim->metric, dim->value_type, dim->multiplier, dim->divider);
1133 }
@@ -1459,7 +1469,7 @@ static inline void statsd_flush_timer_or_histogram(STATSD_METRIC *m, const char
1469 netdata_mutex_lock(&m->histogram.ext->mutex);
1470
1471 int updated = 0;
1462 - if(m->count && !m->reset) {
1472 + if(m->count && !m->reset && m->histogram.ext->used > 0) {
1473 size_t len = m->histogram.ext->used;
1474 long double *series = m->histogram.ext->values;
1475 sort_series(series, len);
@@ -1467,11 +1477,16 @@ static inline void statsd_flush_timer_or_histogram(STATSD_METRIC *m, const char
1477 m->histogram.ext->last_min = (collected_number)roundl(series[0] * STATSD_DECIMAL_DETAIL);
1478 m->histogram.ext->last_max = (collected_number)roundl(series[len - 1] * STATSD_DECIMAL_DETAIL);
1479 m->last = (collected_number)roundl(average(series, len) * STATSD_DECIMAL_DETAIL);
1470 - m->histogram.ext->last_percentile = (collected_number)roundl(average(series, (size_t)floor((double)len * statsd.histogram_percentile / 100.0)) * STATSD_DECIMAL_DETAIL);
1480 m->histogram.ext->last_median = (collected_number)roundl(median_on_sorted_series(series, len) * STATSD_DECIMAL_DETAIL);
1481 m->histogram.ext->last_stddev = (collected_number)roundl(standard_deviation(series, len) * STATSD_DECIMAL_DETAIL);
1482 m->histogram.ext->last_sum = (collected_number)roundl(sum(series, len) * STATSD_DECIMAL_DETAIL);
1483
1484 + size_t pct_len = (size_t)floor((double)len * statsd.histogram_percentile / 100.0);
1485 + if(pct_len < 1)
1486 + m->histogram.ext->last_percentile = (collected_number)(series[0] * STATSD_DECIMAL_DETAIL);
1487 + else
1488 + m->histogram.ext->last_percentile = (collected_number)roundl(average(series, pct_len) * STATSD_DECIMAL_DETAIL);
1489 +
1490 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,
1491 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);
1492
@@ -1626,10 +1641,10 @@ static inline void statsd_update_app_chart(STATSD_APP *app, STATSD_APP_CHART *ch
1641
1642 STATSD_APP_CHART_DIM *dim;
1643 for(dim = chart->dimensions; dim ;dim = dim->next) {
1629 - if(unlikely(dim->value_ptr)) {
1630 - if(unlikely(!dim->rd))
1631 - dim->rd = rrddim_add(chart->st, dim->name, NULL, dim->multiplier, dim->divider, dim->algorithm);
1644 + if(unlikely(!dim->rd))
1645 + dim->rd = rrddim_add(chart->st, dim->name, NULL, dim->multiplier, dim->divider, dim->algorithm);
1646
1647 + if(unlikely(dim->value_ptr)) {
1648 debug(D_STATSD, "updating dimension '%s' (%s) of chart '%s' (%s) for app '%s' with value " COLLECTED_NUMBER_FORMAT, dim->name, dim->rd->id, chart->id, chart->st->id, app->name, *dim->value_ptr);
1649 rrddim_set_by_pointer(chart->st, dim->rd, *dim->value_ptr);
1650 }