Group by time and aggregate in PromQL/MetricsQL

4.9k views Asked by At

I have a metric say x, of type gauge, And the values are reported every 5m.

Now I want to make a query such that, I get sum of values in each hour in a day.

Exmaple: from 3PM to 5PM, the gauge values are 1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,2,2,2,2,2 reported every 5 minutes - total 60 values

The result of my query should be 3PM-4PM -> 45 and 4PM-5PM -> 45 (sum of all values in the hour)

TIA

1

There are 1 answers

0
sskrlj On

See Prometheus count query for a particular period

Just use sum_over_time(x[1h]) instead and 3600 as resolution/step.