Grafana Alerting
Grafana-managed rules and when to use them instead
Grafana has its own alerting engine, built into the same UI as the dashboards. It's a full alternative to Prometheus rules plus Alertmanager, and it raises an obvious question: which should you use?
How Grafana alerting works
A Grafana-managed alert rule has:
- Queries against any data source: Prometheus, Loki, Postgres, CloudWatch, ClickHouse...
- Expressions that reduce and compare the results: Reduce
(last, mean, max), Math (
$A / $B > 0.05), Threshold. - A pending period (the same idea as
for) and labels. - Notification policies, a routing tree like Alertmanager's, and contact points (receivers).
The Grafana server evaluates the rules itself, on a schedule, and stores state in its database.
You'll find it all under Alerting in the left menu: Alert rules, Contact points, Notification policies, Silences. This stack also provisions an Alertmanager data source, so Grafana can show and silence the alerts from the Prometheus-managed pipeline too. Pick it in the drop-down at the top of the Alerting pages.
Prometheus rules vs Grafana rules
| Prometheus rules + Alertmanager | Grafana-managed alerts | |
|---|---|---|
| Data sources | Prometheus only | Any Grafana data source, and mixing them |
| Where it runs | Next to the data; keeps working if Grafana is down | In Grafana; Grafana must be up and able to query |
| Config | YAML in git, promtool tests | UI, or provisioned YAML/Terraform |
| Testing | promtool test rules | No equivalent unit testing |
| Scale | Proven at very large scale | Fine for moderate rule counts |
| Learning curve | PromQL + YAML | UI-driven, friendlier for non-SREs |
The principle: alerting should depend on as few moving parts as possible. A Prometheus rule needs Prometheus and Alertmanager. A Grafana rule also needs Grafana, its database, and the network path from Grafana to every data source. When things are falling apart, fewer dependencies means your alerts keep working.
A reasonable split:
- Prometheus rules for all infrastructure and service alerts on metrics. They're critical, version-controlled, and tested.
- Grafana alerts for things Prometheus can't see: a SQL query against the Postgres module ("orders table has no rows in the last hour"), log-based conditions in Loki, or a business metric in ClickHouse. Also for teams that don't run their own Prometheus rules.
Provisioning Grafana alerts
Like dashboards, Grafana alert rules, contact points, and notification
policies can be provisioned from files in
grafana/provisioning/alerting/. The easiest way to get the format right
is to build a rule in the UI, then use Export (on the rule or the whole
folder), which produces provisioning YAML:
apiVersion: 1
groups:
- orgId: 1
name: business
folder: Services
interval: 1m
rules:
- uid: no-recent-orders
title: No orders in 15 minutes
condition: C
data:
- refId: A
datasourceUid: prometheus
relativeTimeRange: { from: 900, to: 0 }
model:
expr: sum(increase(http_requests_total{route="/api/orders", status="200"}[15m]))
- refId: B
datasourceUid: __expr__
model: { type: reduce, expression: A, reducer: last }
- refId: C
datasourceUid: __expr__
model: { type: threshold, expression: B, conditions: [{ evaluator: { type: lt, params: [1] } }] }
for: 5m
labels:
severity: warningDon't define the same alert in both systems. It's tempting to recreate a Prometheus alert in Grafana "so it shows up in the UI." Now two pipelines page for one problem, with different grouping and silences. Grafana can already display Prometheus alerts through the Alertmanager data source.
Lab
- In Grafana, open Alerting → Alert rules, choose the Alertmanager data source at the top, and find the alerts from Prometheus.
- Create a Grafana-managed rule: "fewer than 1 order in 15 minutes", as
in the YAML above. Set its contact point to a webhook at
http://demo-app:8080/webhook/grafana. - Make it fire:
docker stop loadgen. Wait for it to arrive indocker logs demo-app. Thendocker start loadgen. - Export the rule as provisioning YAML and look at the structure.