How does the rate() function work, and why use it on counters? [Basic]
Answer
rate() calculates the per-second average increase of a counter over a range window and accounts for counter resets. It should be used on counters because raw counters only show lifetime totals and are not useful for current traffic or error rate.
Technical explanation
Counters reset when a process restarts, and rate() handles that reset logic.
The range should be several scrape intervals long; for a 30-second scrape interval, 5 minutes is a common starting point.
Use increase() when you want the total increase over the window rather than a per-second rate.
Hands-on example
Example: requests per second = sum(rate(http_requests_total[5m])) by (service). Five-minute error percentage = 100 * sum(rate(http_requests_total{status=~'5..'}[5m])) / sum(rate(http_requests_total[5m])).
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More Observability interview questions
- What is PromQL, and what is an instant vector versus a range vector? [Basic]
- What is the difference between rate() and irate()? [Basic]
- What is the Pushgateway, and why is it discouraged for most cases? [Basic]
- How do you compute a 95th percentile latency from a histogram in PromQL (histogram_quantile)? [Basic]
- What is the difference between an exporter and instrumenting your app directly? [Basic]
- What is a recording rule, and when would you use one? [Basic]
- What is a scrape target, and how does service discovery find them? [Basic]
- What is an alerting rule, and how does it differ from a recording rule? [Basic]