added "sum" and "incremental-sum" grouping methods; the default grouping was faulty set to "max" - it is now "average" according to documentation
Costa Tsaousis (ktsaou) committed
Jun 5, 2016 at 19:25 UTC
5671ecd40ddd7526b515e7a203d6c34c96cb0043
4 files changed
+31
-10
src/rrd2json.c
+14
@@ -1379,6 +1379,7 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1379
// -------------------------------------------------------------------------
1380
// temp arrays for keeping values per dimension
1381
1382
+ calculated_number last_values[dimensions]; // keep the last value of each dimension
1383
calculated_number group_values[dimensions]; // keep sums when grouping
1384
long group_counts[dimensions]; // keep the number of values added to group_values
1385
uint8_t group_options[dimensions];
@@ -1389,6 +1390,7 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1390
RRDDIM *rd;
1391
long c;
1392
for( rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++) {
1393
+ last_values[c] = 0;
1394
group_values[c] = 0;
1395
group_counts[c] = 0;
1396
group_options[c] = 0;
@@ -1478,6 +1480,14 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1480
case GROUP_AVERAGE:
1481
group_values[c] += value;
1482
break;
1483
+
1484
+ case GROUP_INCREMENTAL_SUM:
1485
+ if(unlikely(slot == start_at_slot))
1486
+ last_values[c] = value;
1487
+
1488
+ group_values[c] = value - last_values[c];
1489
+ last_values[c] = value;
1490
+ break;
1491
}
1492
}
1493
@@ -1504,9 +1514,13 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1514
co[c] |= RRDR_EMPTY;
1515
}
1516
else if(unlikely(group_method == GROUP_AVERAGE)) {
1517
+ // GROUP_AVERAGE
1518
cn[c] = group_values[c] / group_counts[c];
1519
}
1520
else {
1521
+ // GROUP_SUM
1522
+ // GROUP_MAX
1523
+ // GROUP_INCREMENTAL_SUM
1524
cn[c] = group_values[c];
1525
}
1526
src/rrd2json.h
+4
-3
@@ -35,9 +35,10 @@ extern char *hostname;
35
#define DATASOURCE_FORMAT_SSV_COMMA "ssvcomma"
36
#define DATASOURCE_FORMAT_CSV_JSON_ARRAY "csvjsonarray"
37
38
-#define GROUP_AVERAGE 0
39
-#define GROUP_MAX 1
40
-#define GROUP_SUM 2
38
+#define GROUP_AVERAGE 0
39
+#define GROUP_MAX 1
40
+#define GROUP_SUM 2
41
+#define GROUP_INCREMENTAL_SUM 3
42
43
#define RRDR_OPTION_NONZERO 0x00000001 // don't output dimensions will just zero values
44
#define RRDR_OPTION_REVERSED 0x00000002 // output the rows in reverse order (oldest to newest)
src/web_client.c
+9
-3
@@ -629,7 +629,13 @@ int web_client_api_request_v1_data_group(char *name)
629
else if(!strcmp(name, "average"))
630
return GROUP_AVERAGE;
631
632
- return GROUP_MAX;
632
+ else if(!strcmp(name, "sum"))
633
+ return GROUP_SUM;
634
+
635
+ else if(!strcmp(name, "incremental-sum"))
636
+ return GROUP_INCREMENTAL_SUM;
637
+
638
+ return GROUP_AVERAGE;
639
}
640
641
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) {
717
, *label_color = NULL
718
, *value_color = NULL;
719
714
- int group = GROUP_MAX;
720
+ int group = GROUP_AVERAGE;
721
uint32_t options = 0x00000000;
722
723
while(url) {
@@ -847,7 +853,7 @@ int web_client_api_request_v1_data(struct web_client *w, char *url)
853
, *after_str = NULL
854
, *points_str = NULL;
855
850
- int group = GROUP_MAX;
856
+ int group = GROUP_AVERAGE;
857
uint32_t format = DATASOURCE_JSON;
858
uint32_t options = 0x00000000;
859
web/netdata-swagger.yaml
+4
-4
@@ -89,10 +89,10 @@ paths:
89
default: 20
90
- name: group
91
in: query
92
- 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).'
92
+ 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).'
93
required: true
94
type: string
95
- enum: [ 'max', 'average' ]
95
+ enum: [ 'max', 'average', 'sum', 'incremental-sum' ]
96
default: 'average'
97
allowEmptyValue: false
98
- name: format
@@ -184,10 +184,10 @@ paths:
184
default: 0
185
- name: group
186
in: query
187
- 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).'
187
+ 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).'
188
required: true
189
type: string
190
- enum: [ 'max', 'average' ]
190
+ enum: [ 'max', 'average', 'sum', 'incremental-sum' ]
191
default: 'average'
192
allowEmptyValue: false
193
- name: options