Grafana: Grafana Alert Rules
A Grafana alert rule is an alert that Grafana itself evaluates, using a query against its data source. It watches the same ShopSentry latency as the Prometheus rules, but it lives in Grafana, not in Prometheus.
The query: p95 latency
The rule queries the same p95 latency as the dashboard panel.
histogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket{job="shopsentry"}[5m])))Reduce to one number, then check it
The last value is checked against the 0.5 second threshold.
B: reduce A with last
C: threshold B above 0.5Create the rule through the API
The provisioning call creates the rule in the ShopSentry folder.
curl -u admin:admin123 -X POST http://127.0.0.1:13104/api/v1/provisioning/alert-rules -d @grafana-rule.jsonExample
curl -s -u admin:admin123 http://127.0.0.1:13104/api/prometheus/grafana/api/v1/rulesKey points
- A Grafana-managed rule is a rule that Grafana stores and evaluates itself.
- The rule runs a query, reduces the result to one number, and checks it against a threshold.
- Here the query is the p95 latency, reduced to its last value, checked against 0.5 seconds.
- The for setting of 1 minute means the value must stay above the threshold for a minute.
- A Grafana rule sends its notification to a contact point, the place a Grafana alert sends to.
- A Prometheus rule lives in a rule file and is checked by Prometheus; a Grafana rule lives in Grafana.
- Grafana rules can alert on any data source, not only Prometheus.
In this example, the Grafana rule was created through the API in the ShopSentry folder and read back from the running Grafana 13.3.1. Its state is inactive because the p95 latency sits near 0.005 seconds, far below the 0.5 second threshold. The rule is a Grafana-managed rule, separate from the Prometheus rules in the rule file.
Note
Pick one owner for each alert, so the same failure never pages twice.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What is the main difference between a Grafana alert rule and a Prometheus alerting rule?