पाठ 11 / 25
rate, irate and increase
Turning counters into speeds.
Per-second rates that handle resets
rate(counter[5m]) gives the average per-second increase over the window and automatically handles counter resets after restarts. increase(counter[1h]) gives the total increase over the window (rate times the window length). irate uses only the last two samples, which is spiky and better suited to fast-moving graphs than alerts. Use a window of at least four times the scrape interval so each window contains enough samples. Always apply rate before aggregating with sum.
Rates in practice
Common queries.
# requests per second per instance, averaged over 5 minutes
rate(http_requests_total{job="orders-api"}[5m])
# total requests in the last hour
sum(increase(http_requests_total{job="orders-api"}[1h]))
# wrong order: summing counters first breaks reset handling
# rate(sum(http_requests_total)[5m]) <- avoidrate then sum, never sum then rate
Summing raw counters hides individual resets, so the resulting rate shows false drops and spikes.
त्वरित जाँच: Why use rate() on a counter instead of graphing it directly?
- Graphing counters is not allowed
- Counters are always zero
- rate() converts gauges to counters
- Counters only grow; rate shows the per-second change and handles resets
Answer
Counters only grow; rate shows the per-second change and handles resets — The speed is what matters.