Add GROUPBY and REDUCE support
gkorland opened this issue · comments
Expected argument extension to TS.MRANGE
: GROUPBY <label> REDUCE <reducer>
TS.MRANGE 1451679382646 1451682982646 WITHLABELS
AGGREGATION MAX 60000
FILTER measurement=cpu
fieldname=usage_user
hostname=(host_9,host_3,host_5,host_1,host_7,host_2,host_8,host_4)
GROUPBY hostname REDUCE MAX
Documentation extension:
-
GROUPBY - Aggregate results across different time series, grouped by the provided label name.
For OSS clustered databases, RedisGears is required to be present.When combined with
AGGREGATION
the groupby/reduce is applied post aggregation stage.-
label - label name to group series by.
-
reducer - Reducer type used to aggregate series that share the same label value. Available reducers: sum, min, max.
-
Note: The resulting series will contain 3 labels with the following label array structure:
<label>=<groupbyvalue>
: containing the label name and label value.__reducer__=<reducer>
: containing the used reducer.__source__=key1,key2,key3
: containing the source time series used to compute the grouped serie.
-
Example of the above features:
Query time series with metric=cpu, group them by metric_name reduce max
127.0.0.1:6379> TS.ADD ts1 1 90 labels metric cpu metric_name system
(integer) 1
127.0.0.1:6379> TS.ADD ts1 2 45
(integer) 2
127.0.0.1:6379> TS.ADD ts2 2 99 labels metric cpu metric_name user
(integer) 2
127.0.0.1:6379> TS.MRANGE - + WITHLABELS FILTER metric=cpu GROUPBY metric_name REDUCE max
1) 1) "metric_name=system"
2) 1) 1) "metric_name"
2) "system"
2) 1) "__reducer__"
2) "max"
3) 1) "__source__"
2) "ts1"
3) 1) 1) (integer) 1
2) 90
2) 1) (integer) 2
2) 45
2) 1) "metric_name=user"
2) 1) 1) "metric_name"
2) "user"
2) 1) "__reducer__"
2) "max"
3) 1) "__source__"
2) "ts2"
3) 1) 1) (integer) 2
2) 99