Learn Labs
Rules, Alerting & SLOs

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:

  1. Queries against any data source: Prometheus, Loki, Postgres, CloudWatch, ClickHouse...
  2. Expressions that reduce and compare the results: Reduce (last, mean, max), Math ($A / $B > 0.05), Threshold.
  3. A pending period (the same idea as for) and labels.
  4. 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 + AlertmanagerGrafana-managed alerts
Data sourcesPrometheus onlyAny Grafana data source, and mixing them
Where it runsNext to the data; keeps working if Grafana is downIn Grafana; Grafana must be up and able to query
ConfigYAML in git, promtool testsUI, or provisioned YAML/Terraform
Testingpromtool test rulesNo equivalent unit testing
ScaleProven at very large scaleFine for moderate rule counts
Learning curvePromQL + YAMLUI-driven, friendlier for non-SREs

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: warning

Lab

  1. In Grafana, open Alerting → Alert rules, choose the Alertmanager data source at the top, and find the alerts from Prometheus.
  2. 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.
  3. Make it fire: docker stop loadgen. Wait for it to arrive in docker logs demo-app. Then docker start loadgen.
  4. Export the rule as provisioning YAML and look at the structure.

On this page