diff options
Diffstat (limited to '')
-rw-r--r-- | src/web/api/formatters/value/README.md | 28 | ||||
-rw-r--r-- | src/web/api/formatters/value/value.c (renamed from web/api/formatters/value/value.c) | 68 | ||||
-rw-r--r-- | src/web/api/formatters/value/value.h (renamed from web/api/formatters/value/value.h) | 0 |
3 files changed, 63 insertions, 33 deletions
diff --git a/src/web/api/formatters/value/README.md b/src/web/api/formatters/value/README.md new file mode 100644 index 000000000..3599a836e --- /dev/null +++ b/src/web/api/formatters/value/README.md @@ -0,0 +1,28 @@ +<!-- +title: "Value formatter" +custom_edit_url: https://github.com/netdata/netdata/edit/master/src/web/api/formatters/value/README.md +sidebar_label: "Value formatter" +learn_status: "Published" +learn_topic_type: "References" +learn_rel_path: "Developers/Web/Api/Formatters" +--> + +# Value formatter + +The Value formatter presents [results of database queries](https://github.com/netdata/netdata/blob/master/src/web/api/queries/README.md) as a single value. + +To calculate the single value to be returned, it sums the values of all dimensions. + +The Value formatter respects the following API `&options=`: + +| option | supported | description | +|:----: |:-------: |:---------- | +| `percent` | yes | to replace all values with their percentage over the row total| +| `abs` | yes | to turn all values positive, before using them | +| `min2max` | yes | to return the delta from the minimum value to the maximum value (across dimensions)| + +The Value formatter is not exposed by the API by itself. +Instead it is used by the [`ssv`](https://github.com/netdata/netdata/blob/master/src/web/api/formatters/ssv/README.md) formatter +and [health monitoring queries](https://github.com/netdata/netdata/blob/master/src/health/README.md). + + diff --git a/web/api/formatters/value/value.c b/src/web/api/formatters/value/value.c index 1d07f62f6..0ec1b1265 100644 --- a/web/api/formatters/value/value.c +++ b/src/web/api/formatters/value/value.c @@ -2,7 +2,6 @@ #include "value.h" - inline NETDATA_DOUBLE rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *all_values_are_null, NETDATA_DOUBLE *anomaly_rate) { size_t c; @@ -10,61 +9,64 @@ inline NETDATA_DOUBLE rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *all RRDR_VALUE_FLAGS *co = &r->o[ i * r->d ]; NETDATA_DOUBLE *ar = &r->ar[ i * r->d ]; - NETDATA_DOUBLE sum = 0, min = 0, max = 0, v; - int all_null = 1, init = 1; + NETDATA_DOUBLE sum = 0, min = NAN, max = NAN, v = NAN; + size_t dims = 0; NETDATA_DOUBLE total_anomaly_rate = 0; // for each dimension for (c = 0; c < r->d ; c++) { - if(!rrdr_dimension_should_be_exposed(r->od[c], options)) + if(unlikely(!rrdr_dimension_should_be_exposed(r->od[c], options))) + continue; + + if(unlikely((co[c] & RRDR_VALUE_EMPTY))) continue; NETDATA_DOUBLE n = cn[c]; - if(unlikely(init)) { - if(n > 0) { - min = 0; - max = n; - } - else { - min = n; - max = 0; - } - init = 0; - } + if(unlikely(!dims)) + min = max = n; - if(likely(!(co[c] & RRDR_VALUE_EMPTY))) { - all_null = 0; - sum += n; - } + sum += n; - if(n < min) min = n; - if(n > max) max = n; + if (n < min) min = n; + if (n > max) max = n; total_anomaly_rate += ar[c]; - } - if(anomaly_rate) { - if(!r->d) *anomaly_rate = 0; - else *anomaly_rate = total_anomaly_rate / (NETDATA_DOUBLE)r->d; + dims++; } - if(unlikely(all_null)) { - if(likely(all_values_are_null)) + if(!dims) { + if(anomaly_rate) + *anomaly_rate = 0; + + if(all_values_are_null) *all_values_are_null = 1; - return 0; - } - else { - if(likely(all_values_are_null)) - *all_values_are_null = 0; + + return (options & RRDR_OPTION_NULL2ZERO) ? 0 : NAN; } - if(options & RRDR_OPTION_MIN2MAX) + if(anomaly_rate) + *anomaly_rate = total_anomaly_rate / (NETDATA_DOUBLE)dims; + + if(all_values_are_null) + *all_values_are_null = 0; + + if(options & RRDR_OPTION_DIMS_MIN2MAX) v = max - min; + else if(options & RRDR_OPTION_DIMS_AVERAGE) + v = sum / (NETDATA_DOUBLE)dims; + else if(options & RRDR_OPTION_DIMS_MIN) + v = min; + else if(options & RRDR_OPTION_DIMS_MAX) + v = max; else v = sum; + if((options & RRDR_OPTION_NULL2ZERO) && (isnan(v) || isinf(v))) + v = 0; + return v; } diff --git a/web/api/formatters/value/value.h b/src/web/api/formatters/value/value.h index 072ca14f8..072ca14f8 100644 --- a/web/api/formatters/value/value.h +++ b/src/web/api/formatters/value/value.h |