Interview Observability

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])).

Preparing for an interview?

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

← All Observability questions