]> arthur.barton.de Git - netdata.git/commitdiff
the API now also support "min" group method
authorCosta Tsaousis <costa@tsaousis.gr>
Tue, 16 Aug 2016 10:36:44 +0000 (13:36 +0300)
committerCosta Tsaousis <costa@tsaousis.gr>
Tue, 16 Aug 2016 10:36:44 +0000 (13:36 +0300)
src/rrd2json.c
src/rrd2json.h
src/web_client.c
web/netdata-swagger.yaml

index cb7d333babbfb43e7daed76feb5a4477289857e0..6306d9faec68d6d8f58a5f33e8661ade38afdb46 100644 (file)
@@ -1370,7 +1370,7 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
     long c;
     for( rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++) {
         last_values[c] = 0;
-        group_values[c] = 0;
+        group_values[c] = (group_method == GROUP_MAX || group_method == GROUP_MIN)?NAN:0;
         group_counts[c] = 0;
         group_options[c] = 0;
         found_non_zero[c] = 0;
@@ -1449,14 +1449,22 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
                 group_options[c] |= RRDR_RESET;
 
             switch(group_method) {
+                case GROUP_MIN:
+                    if(unlikely(isnan(group_values[c])) ||
+                            fabsl(value) < fabsl(group_values[c]))
+                        group_values[c] = value;
+                    break;
+
                 case GROUP_MAX:
-                    if(unlikely(fabsl(value) > fabsl(group_values[c])))
+                    if(unlikely(isnan(group_values[c])) ||
+                            fabsl(value) > fabsl(group_values[c]))
                         group_values[c] = value;
                     break;
 
                 default:
                 case GROUP_SUM:
                 case GROUP_AVERAGE:
+                case GROUP_UNDEFINED:
                     group_values[c] += value;
                     break;
 
@@ -1491,23 +1499,39 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
                 if(unlikely(group_counts[c] == 0)) {
                     cn[c] = 0.0;
                     co[c] |= RRDR_EMPTY;
-                }
-                else if(unlikely(group_method == GROUP_AVERAGE)) {
-                    // GROUP_AVERAGE
-                    cn[c] = group_values[c] / group_counts[c];
+                    group_values[c] = (group_method == GROUP_MAX || group_method == GROUP_MIN)?NAN:0;
                 }
                 else {
-                    // GROUP_SUM
-                    // GROUP_MAX
-                    // GROUP_INCREMENTAL_SUM
-                    cn[c] = group_values[c];
-                }
+                    switch(group_method) {
+                        case GROUP_MIN:
+                        case GROUP_MAX:
+                            if(unlikely(isnan(group_values[c])))
+                                cn[c] = 0;
+                            else {
+                                cn[c] = group_values[c];
+                                group_values[c] = NAN;
+                            }
+                            break;
+
+                        case GROUP_SUM:
+                        case GROUP_INCREMENTAL_SUM:
+                            cn[c] = group_values[c];
+                            group_values[c] = 0;
+                            break;
+
+                        default:
+                        case GROUP_AVERAGE:
+                        case GROUP_UNDEFINED:
+                            cn[c] = group_values[c] / group_counts[c];
+                            group_values[c] = 0;
+                            break;
+                    }
 
-                if(cn[c] < r->min) r->min = cn[c];
-                if(cn[c] > r->max) r->max = cn[c];
+                    if(cn[c] < r->min) r->min = cn[c];
+                    if(cn[c] > r->max) r->max = cn[c];
+                }
 
-                // reset them for the next loop
-                group_values[c] = 0;
+                // reset for the next loop
                 group_counts[c] = 0;
                 group_options[c] = 0;
             }
index 99400346efd20413379a178c5b553bf468567b91..308c6972a77dbde14965c141bb3cc29c4c2d51d9 100644 (file)
@@ -30,10 +30,12 @@ extern char *hostname;
 #define DATASOURCE_FORMAT_SSV_COMMA "ssvcomma"
 #define DATASOURCE_FORMAT_CSV_JSON_ARRAY "csvjsonarray"
 
-#define GROUP_AVERAGE           0
-#define GROUP_MAX               1
-#define GROUP_SUM               2
-#define GROUP_INCREMENTAL_SUM   3
+#define GROUP_UNDEFINED         0
+#define GROUP_AVERAGE           1
+#define GROUP_MIN               2
+#define GROUP_MAX               3
+#define GROUP_SUM               4
+#define GROUP_INCREMENTAL_SUM   5
 
 #define RRDR_OPTION_NONZERO         0x00000001 // don't output dimensions will just zero values
 #define RRDR_OPTION_REVERSED        0x00000002 // output the rows in reverse order (oldest to newest)
index 8976e925cb8bbf74d74f3ebc31509c18668a2b67..6b454b7867ac49b92e4e7cc4861f1b172503bc54 100644 (file)
@@ -553,12 +553,15 @@ uint32_t web_client_api_request_v1_data_google_format(char *name)
 
 int web_client_api_request_v1_data_group(char *name, int def)
 {
-    if(!strcmp(name, "max"))
-        return GROUP_MAX;
-
-    else if(!strcmp(name, "average"))
+    if(!strcmp(name, "average"))
         return GROUP_AVERAGE;
 
+    else if(!strcmp(name, "min"))
+        return GROUP_MIN;
+
+    else if(!strcmp(name, "max"))
+        return GROUP_MAX;
+
     else if(!strcmp(name, "sum"))
         return GROUP_SUM;
 
index 85e4c85090630207c8b7a59f22b2e89de1fdad11..5d01a73f4cbc84bf69807d6bcc1872414a09cd82 100644 (file)
@@ -89,10 +89,10 @@ paths:
           default: 20
         - name: group
           in: query
-          description: 'The grouping method. If multiple collected values are to be grouped in order to return fewer points, this parameters defines the method of grouping. 4 methods are supported, "max", "average", "sum", "incremental-sum". "max" is actually calculated on the absolute value collected (so it works for both positive and negative dimesions to return the most extreme value in either direction).'
+          description: 'The grouping method. If multiple collected values are to be grouped in order to return fewer points, this parameters defines the method of grouping. methods supported "min", "max", "average", "sum", "incremental-sum". "max" is actually calculated on the absolute value collected (so it works for both positive and negative dimesions to return the most extreme value in either direction).'
           required: true
           type: string
-          enum: [ 'max', 'average', 'sum', 'incremental-sum' ]
+          enum: [ 'min', 'max', 'average', 'sum', 'incremental-sum' ]
           default: 'average'
           allowEmptyValue: false
         - name: format
@@ -184,10 +184,10 @@ paths:
           default: 0
         - name: group
           in: query
-          description: 'The grouping method. If multiple collected values are to be grouped in order to return fewer points, this parameters defines the method of grouping. 4 methods are supported, "max", "average", "sum", "incremental-sum". "max" is actually calculated on the absolute value collected (so it works for both positive and negative dimesions to return the most extreme value in either direction).'
+          description: 'The grouping method. If multiple collected values are to be grouped in order to return fewer points, this parameters defines the method of grouping. methods are supported "min", "max", "average", "sum", "incremental-sum". "max" is actually calculated on the absolute value collected (so it works for both positive and negative dimesions to return the most extreme value in either direction).'
           required: true
           type: string
-          enum: [ 'max', 'average', 'sum', 'incremental-sum' ]
+          enum: [ 'min', 'max', 'average', 'sum', 'incremental-sum' ]
           default: 'average'
           allowEmptyValue: false
         - name: options