PromQL avg vs avg_over_time

PromQL avg vs avg_over_time

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.

Why cant 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 (...)

PromQL avg vs avg_over_time

Leave a Reply

Your email address will not be published.