]> arthur.barton.de Git - netdata.git/commitdiff
added "sum" and "incremental-sum" grouping methods; the default grouping was faulty...
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 5 Jun 2016 16:25:23 +0000 (19:25 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 5 Jun 2016 16:25:23 +0000 (19:25 +0300)
src/rrd2json.c
src/rrd2json.h
src/web_client.c
web/netdata-swagger.yaml

index 905e699e03e85c605fec292c88ae18b4971437d8..f3c2e198f0faacfc37f6c2180e9cc0abba3bcccd 100644 (file)
@@ -1379,6 +1379,7 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
        // -------------------------------------------------------------------------
        // temp arrays for keeping values per dimension
 
+       calculated_number       last_values[dimensions]; // keep the last value of each dimension
        calculated_number       group_values[dimensions]; // keep sums when grouping
        long                            group_counts[dimensions]; // keep the number of values added to group_values
        uint8_t                         group_options[dimensions];
@@ -1389,6 +1390,7 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
        RRDDIM *rd;
        long c;
        for( rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++) {
+               last_values[c] = 0;
                group_values[c] = 0;
                group_counts[c] = 0;
                group_options[c] = 0;
@@ -1478,6 +1480,14 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
                                case GROUP_AVERAGE:
                                        group_values[c] += value;
                                        break;
+
+                               case GROUP_INCREMENTAL_SUM:
+                                       if(unlikely(slot == start_at_slot))
+                                               last_values[c] = value;
+
+                                       group_values[c] = value - last_values[c];
+                                       last_values[c] = value;
+                                       break;
                        }
                }
 
@@ -1504,9 +1514,13 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
                                        co[c] |= RRDR_EMPTY;
                                }
                                else if(unlikely(group_method == GROUP_AVERAGE)) {
+                                       // GROUP_AVERAGE
                                        cn[c] = group_values[c] / group_counts[c];
                                }
                                else {
+                                       // GROUP_SUM
+                                       // GROUP_MAX
+                                       // GROUP_INCREMENTAL_SUM
                                        cn[c] = group_values[c];
                                }
 
index 57b11b5b255d6636471d78195a3dbedc19a47154..42a7e20097a74974a2ba554a73e9dfe88815c82a 100644 (file)
@@ -35,9 +35,10 @@ 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_AVERAGE                  0
+#define GROUP_MAX                              1
+#define GROUP_SUM                              2
+#define GROUP_INCREMENTAL_SUM  3
 
 #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 a41ccbb5d7daace894737783026f5569d21e629b..92802eece937a120bffacd77592cf497187dd37c 100644 (file)
@@ -629,7 +629,13 @@ int web_client_api_request_v1_data_group(char *name)
        else if(!strcmp(name, "average"))
                return GROUP_AVERAGE;
 
-       return GROUP_MAX;
+       else if(!strcmp(name, "sum"))
+               return GROUP_SUM;
+
+       else if(!strcmp(name, "incremental-sum"))
+               return GROUP_INCREMENTAL_SUM;
+
+       return GROUP_AVERAGE;
 }
 
 int web_client_api_request_v1_charts(struct web_client *w, char *url)
@@ -711,7 +717,7 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
                        , *label_color = NULL
                        , *value_color = NULL;
 
-       int group = GROUP_MAX;
+       int group = GROUP_AVERAGE;
        uint32_t options = 0x00000000;
 
        while(url) {
@@ -847,7 +853,7 @@ int web_client_api_request_v1_data(struct web_client *w, char *url)
                        , *after_str = NULL
                        , *points_str = NULL;
 
-       int group = GROUP_MAX;
+       int group = GROUP_AVERAGE;
        uint32_t format = DATASOURCE_JSON;
        uint32_t options = 0x00000000;
 
index 167dd8baccbc19ca946126120aed287c47fb2671..85e4c85090630207c8b7a59f22b2e89de1fdad11 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. Two methods are supported, "max" and "average". "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. 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).'
           required: true
           type: string
-          enum: [ 'max', 'average' ]
+          enum: [ '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. Two methods are supported, "max" and "average". "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. 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).'
           required: true
           type: string
-          enum: [ 'max', 'average' ]
+          enum: [ 'max', 'average', 'sum', 'incremental-sum' ]
           default: 'average'
           allowEmptyValue: false
         - name: options