Skip to main content
This article explains how Grafana-managed alerts operate and how to construct alert rules that reliably surface real problems. It walks through a concrete PromQL example for alerting on error rate, then breaks down the key alert rule components: query, condition, evaluation behavior, labels, annotations, and the alert state machine.

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:
Important: when Grafana evaluates an alert rule, the alert query is evaluated at a single, most-recent timestamp and yields a single scalar value (like a stat or gauge). Grafana does not evaluate a time range for the alert condition the way a time-series panel does; it repeatedly samples the query on the evaluation schedule.

Alert rule components

Below is a concise reference for the pieces that make up a Grafana alert rule.
A diagram titled "Grafana Alert Rules" showing a flowchart from "PromQL Expression" to "Condition" to "Evaluation Behavior" and then to Labels and Annotations. A side panel explains evaluation intervals and includes example graphs showing when an alert will or won't fire.

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).
  • for duration: the length of time the condition must continuously remain true before Grafana transitions the alert to the firing state.
Use the 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 severity with values like critical or warning.
  • Annotations: for human context. Include templated summaries, descriptions, and dashboard links so responders can quickly assess and act.
Example annotations block:
Note that templated fields such as {{ $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 for duration is satisfied.
  • Alerting → Normal when the condition clears (resolved).
This state progression (Normal → Pending → Alerting → Normal) makes the for duration essential for distinguishing brief spikes from sustained incidents.
A diagram titled "Grafana Alert State Flow" showing three states — Normal, Pending, and Alerting — connected by arrows. It indicates "Breached" moves Normal→Pending, "For: 5m" moves Pending→Alerting, and a "Resolved" arrow returns to Normal, with a bell icon for notification.

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 for to reduce noise: tune for to 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

We’ve covered how Prometheus queries, Grafana alert conditions, evaluation intervals, 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.

Watch Video