Why is the sum_over_time(foo[1m]) equal to 6x avg_over_time(foo[1m])?

Viewed 21

I have a StatsD counter foo. I want to make a graph showing the number of times per minute this counter is incremented. I think I should use either sum_over_time or avg_over_time.

I observe that when I graph sum_over_time(foo[1m]) vs avg_over_time(foo[1m]), the former is always exactly 6x the latter. This may be related to the fact that 1m is 6x my StatsD flush interval of 10s.

What are these two functions doing? Why is one 6x the other? Which one should I use if I want to compute the rate of increments per minute?

1 Answers

In your final question you hinted at the answer (rate). Since you want to calculate the rate of change of a given counter you are looking for the rate function. From the documentation:

rate(v range-vector) calculates the per-second average rate of increase of the time series in the range vector.

Keep in mind that this calculates the per-second rate and you want the per-minute so you would need to adjust it:

rate(my_metric[5m]) * 60

The 5m window here means that it will calculate the per-second rate for a 5m window. You should not use 1m as the window size unless your scrape interval is something like 15s or so, this time window should always be large enough to accommodate around 4 samples.

Related