PromQL Sum over time

9.2k Views Asked by At

i have some issues on summing prometheus values together.

my rows :

METRIC{applicationName="MYAPP", column="MYCOLUMN} = 2
METRIC{applicationName="MYAPP", column="MYCOLUMN} = 2
METRIC{applicationName="MYAPP", column="MYCOLUMN} = 1
METRIC{applicationName="MYAPP", column="MYCOLUMN} = 3
METRIC{applicationName="MYAPP", column="MYCOLUMN} = 1

==== 9

sum(sum_over_time(METRIC{NAME="TEST" , applicationName="MYAPP"} [3h])) by (applicationName)

{applicationName="MYAPP"} value = 27

Should be 9

Basicly what eve i try it is multiplied with 3 (nope its not the time period, already tryed that)

-- Basicly i would like to get thouse values to grafana (7.1) table,

if i get them on to graph (METRIC{applicationName="MYAPP") then total is fine ... Tryed different aproaches and mentioned way is the moust accurate what i have achived..

Same result in primetheus console..

1

There are 1 best solutions below

0
On

I suppose rows above represents what you get if you punch METRIC into Prometheus.

If that's the case, then you got values over different dimensions at the same point in time. And from this, you don't know what those values are over 3h period, which you'd like to sum over.

If you now do sum(METRIC), you'll get 9.

You can punch METRIC[3h] into Prometheus to get those exact values, within 3h period.

Doing sum(sum_over_time(METRIC[3h])) should give you the sum of all values displayed in the experiment above. That seems to be 27. And it seems to me your metric frequency is 1h, and values haven't changed within those 3h and that's why you got 3 x 9 = 27. But it's just my guessing.

I intentionally omitted filters and groups. They're are a bit inconsistent.