An operator needs to query the current, un-extrapolated rate of increase per second over the last 5 minutes for a counter metric named http_requests_total. Which function should they use?
Trap 1: increase(http_requests_total[5m])
increase returns the total growth across the range, not a per-second rate, and it extrapolates to the range boundaries. The operator needs rate, which divides by seconds and is un-extrapolated. increase is tempting for counter growth over a window, and it would be correct when you want the absolute increment, not a rate.
Trap 2: rate(http_requests_total[5m])
rate extrapolates to the range boundaries, so it is not un-extrapolated as the stem requires. The un-extrapolated per-second function is irate, which uses only the last two samples. rate is tempting because it does return a per-second average, and it would be correct when boundary extrapolation is acceptable.
Trap 3: delta(http_requests_total[5m])
delta returns the difference between the first and last sample of a gauge range, with no per-second division and no counter handling. irate gives the un-extrapolated per-second rate. delta is tempting for measuring change over a window, and it would be correct for a gauge such as temperature.
- A
increase(http_requests_total[5m])
Why it fails: increase returns the total growth across the range, not a per-second rate, and it extrapolates to the range boundaries. The operator needs rate, which divides by seconds and is un-extrapolated. increase is tempting for counter growth over a window, and it would be correct when you want the absolute increment, not a rate.
- B
irate(http_requests_total[5m])
irate() calculates the per-second rate using only the last two samples within the range, so it returns the current, un-extrapolated increase rather than a smoothed average. This satisfies the requirement for the instantaneous rate of increase per second over the last 5 minutes.
- C
rate(http_requests_total[5m])
Why it fails: rate extrapolates to the range boundaries, so it is not un-extrapolated as the stem requires. The un-extrapolated per-second function is irate, which uses only the last two samples. rate is tempting because it does return a per-second average, and it would be correct when boundary extrapolation is acceptable.
- D
delta(http_requests_total[5m])
Why it fails: delta returns the difference between the first and last sample of a gauge range, with no per-second division and no counter handling. irate gives the un-extrapolated per-second rate. delta is tempting for measuring change over a window, and it would be correct for a gauge such as temperature.