The on-call phone buzzes at 3 a.m. Two minutes later the alert resolves itself. Nobody slept, and nothing was broken. The usual reaction is to raise the threshold, and the usual result is an alert that now also misses the real incident.
In my Grafana training, the lab runs a small webshop with Prometheus, Loki and Alloy behind it, and one command participants don’t expect on day one: ./labctl.sh chaos errors 5. From that moment the shop throws errors, and the task is to find out what is wrong using only the dashboards and alert rules the team built itself. That test is honest in a way a quiet system never is. Panels that looked fine suddenly hide the spike, and rules that looked strict either stay silent or fire for the wrong reason.
Noisy alerts are a query problem first and a timing problem second
That is why I don’t start with thresholds when a team tells me its alerts are noisy. I start with the query underneath, because an alert can only be as calm as the line it watches. Two mistakes cause most of that noise, and both sit in one line of PromQL.
The first is a raw counter. http_requests_total counts every request since the process started. On a panel it is a line that only goes up, and when a pod restarts it drops back to zero. That drop is a counter reset, not an outage, but a rule built on the raw value cannot tell the difference.
The second is the wrong order. If you add counters up first and take the rate afterwards, a reset on a single instance is buried inside the total, and the graph quietly lies to you. rate() knows how to handle a reset only while it sees each series on its own.
| Query | What you see | Use it for an alert? |
|---|---|---|
http_requests_total | A line that only grows and drops to zero on every restart | No |
rate(sum(http_requests_total)[5m:]) | Aggregated first: a reset on one pod distorts the total | No |
sum(rate(http_requests_total[5m])) | Requests per second for the whole service, resets handled per series | Yes |
sum by (route) (rate(http_requests_total[5m])) | One line per route, everything else summed away | Yes, when the route matters |
The order I teach for an alert that only fires when it should
So this is the order I teach, and the order I use when I review a team’s existing rules:
- Rate first, aggregate second. Apply
rate()to each counter series, thensum()orsum by (…)over the result. Keep only the labels you would actually act on. - Pick a rate window that has enough samples. A tiny window turns every scrape into a spike. In Grafana panels,
$__rate_intervalpicks a window of at least four scrape intervals for you. - Alert on a ratio, not on a count. “5 errors per second” means something different at night and at noon. Errors divided by all requests stays comparable.
- Then set the pending period. A rule that crosses its threshold goes to Pending first, and only fires if the condition still holds when the pending period is over. I set it from “how long can this be broken before a user notices?”, not from “how fast could we react?”.
- Break the system and watch the rule. Trigger the failure on purpose in a test environment. The rule should fire within the time you decided, and stay quiet when you restart a pod.
For a webshop, an error-rate rule built this way looks like this (label names depend on how your app is instrumented):
# Share of failed requests over the last 5 minutes, for the whole shop
sum(rate(http_requests_total{job="webshop", status=~"5.."}[5m]))
/
sum(rate(http_requests_total{job="webshop"}[5m]))
# Alert rule settings in Grafana
# Threshold: is above 0.05 (more than 5 % of requests fail)
# Pending period: 5m (must hold for five minutes)
# Evaluation: every 1m
Run that last step once per failure type your business really cares about, and again whenever someone changes the rule. It takes minutes, and it is the only way to know the alert does what everyone believes it does.
FAQ: rate, sum and Grafana alerts
Why should rate() come before sum() in PromQL?
rate() detects counter resets by looking at each series on its own. If you sum the counters first, a restart on one instance becomes a drop in the total that rate() can no longer recognise as a reset, and the result is distorted. Apply rate() per series, then aggregate with sum().
What is the difference between rate() and increase()?
Both work on counters and handle resets. rate() returns the average per-second rate over the window, increase() returns the total increase over the window. For dashboards and alert thresholds that should stay comparable across time ranges, rate() is usually the better choice.
What is the pending period in Grafana alerting?
When an alert rule crosses its threshold, it first goes to Pending. Only if the condition still holds after the pending period does it switch to Firing and send a notification. Short spikes that recover on their own never reach anyone.
Which rate window should I use?
Large enough to contain several scrapes. A window of at least four scrape intervals is a common rule; in Grafana panels, $__rate_interval calculates such a window from the data source’s scrape interval. For alert rules, use a fixed window like 5m so the rule behaves the same no matter how a dashboard is zoomed.