PromQL avg vs avg_over_time

27.5k Views Asked by At

Over time functions are not supporting by/without syntax. Which is the mathematical difference between using avg_over_time(metric[1h]) and avg(metric[1h])? Can a over time function be replaced with a function (in this case avg) with the same results? Thanks!

3

There are 3 best solutions below

4
On BEST ANSWER

The avg_over_time(m[d]) function performs the following:

  • it selects all the time series with name m
  • then for every selected time series it calculates the average value across raw samples on the time range d preceding every point on the graph.

The avg(m) function performs the following:

  • it selects all the time series with name m
  • then for every selected time series it selects the last raw sample value before every point on the graph. See these docs for more details.
  • then for every point on the graph it calculates the average value across the selected values for every time series.

As you can see, avg_over_time() and avg() are quite different functions - avg_over_time() calculates distinct average values for every selected time series, while avg() calculates average values across the selected time series.

1
On

Why can't you just use

avg(avg_over_time(m[d]))

instead of

sum(sum_over_time(m[d])) by (...) / sum(count_over_time(m[d])) by (...)
0
On
  • avg function return scalar, but avg_over_time return new instant vector.

  • avg function require instance vector parameter, but avg_over_time function require range vector