// -------------------------------------------------------------------------
// 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];
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;
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;
}
}
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];
}
#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)
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)
, *label_color = NULL
, *value_color = NULL;
- int group = GROUP_MAX;
+ int group = GROUP_AVERAGE;
uint32_t options = 0x00000000;
while(url) {
, *after_str = NULL
, *points_str = NULL;
- int group = GROUP_MAX;
+ int group = GROUP_AVERAGE;
uint32_t format = DATASOURCE_JSON;
uint32_t options = 0x00000000;
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
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