Example: alerting on error rate (5xx responses)
A common signal is the percentage of 5xx responses over a recent window. In PromQL you can compute a 5-minute error rate like this:Alert rule components
Below is a concise reference for the pieces that make up a Grafana alert rule.
Conditions and thresholds
The condition is the boolean test that determines if an evaluated scalar should be considered a breach. For example, if your SLO states an error rate < 1%, use a condition like> 1. Conditions are intentionally simple because Grafana evaluates a single scalar per check.
Evaluation behavior: sampling and the for duration
- Evaluation interval: how often Grafana samples the query (for example, every
1m). forduration: the length of time the condition must continuously remain true before Grafana transitions the alert to the firing state.
for window to suppress noisy, short-lived spikes. For example, choose evaluation interval: 1m and for: 5m so only sustained breaches cause notifications.
The
for duration acts as a gate: it prevents alerts from firing on short-lived spikes and reduces alert noise. Balance prompt detection and noise suppression by choosing an appropriate evaluation interval and for window (e.g., evaluate every 1 minute and use for: 5m for sustained breaches).Labels vs. annotations
- Labels: for routing and automated handling. Use labels to determine which escalation policy, PagerDuty service, or Slack channel receives the alert. A common label is
severitywith values likecriticalorwarning. - Annotations: for human context. Include templated summaries, descriptions, and dashboard links so responders can quickly assess and act.
{{ $value | printf "%.2f" }} inject the evaluated scalar into messages and annotation text.
Alert state machine
Grafana uses a three-state model to manage alert lifecycle:
Transitions:
- Normal → Pending when the condition is first breached.
- Pending → Alerting after the full
forduration is satisfied. - Alerting → Normal when the condition clears (resolved).
for duration essential for distinguishing brief spikes from sustained incidents.

Best practices
- Alert on symptoms, not causes: alert on high error rates, latency, or saturation — not on a downstream component’s internal error unless that error directly impacts user experience.
- Keep conditions simple: evaluate a single scalar and test it against a straightforward threshold.
- Use
forto reduce noise: tuneforto filter short-lived spikes while keeping detection timely. - Use labels to route and annotations to help responders: include dashboard links and the evaluated value in annotations.
- Align alerts with SLOs: map alert thresholds and severities to your SLO objectives and escalation policies.
References and further reading
- Grafana Alerting documentation: https://grafana.com/docs/grafana/latest/alerting/
- PromQL basics: https://prometheus.io/docs/prometheus/latest/querying/basics/
- SRE and monitoring best practices: https://landing.google.com/sre/book.html
for durations, labels, and annotations work together to produce reliable, actionable alerts. Though the examples used simple web-service golden signals, the same principles apply in MLOps and other monitoring domains.