Create a Grafana managed alerting rule
Watch this video to learn more about creating alerts:
- In the Grafana menu, click the Alerting (bell) icon to open the Alerting page listing existing alerts.
- Click New alert rule. The new alerting rule page opens where the Grafana managed alerts option is selected by default.
- In Step 1, add queries and expressions to evaluate, and then select the alert condition.
- For queries, select a data source from the drop-down.
- Add one or more or expressions.
- Click Run queries to verify that the query is successful.
- Next, select the query or expression for your alert condition.
In Step 2, specify the alert evaluation interval.
- From the Condition drop-down, select the query or expression to trigger the alert rule.
- For Evaluate every, specify the frequency of evaluation. Must be a multiple of 10 seconds. For examples, ,
30s
. For Evaluate for, specify the duration for which the condition must be true before an alert fires.
In Configure no data and error handling, configure alerting behavior in the absence of data. Use the guidelines in .
- Click Preview alerts to check the result of running the query at this moment. Preview excludes no data and error handling.
- In Step 3, add the rule name, storage location, rule group, as well as additional metadata associated with the rule.
- From the Folder drop-down, select the folder where you want to store the rule.
- For Group, specify a pre-defined group. Newly created rules are appended to the end of the group. Rules within a group are run sequentially at a regular interval, with the same evaluation time.
- Add a description and summary to customize alert messages. Use the guidelines in Annotations and labels for alerting.
- Add Runbook URL, panel, dashboard, and alert IDs.
- Add custom labels.
- Click Save to save the rule or Save and exit to save the rule and go back to the Alerting page.
- Next, create a for the rule.
For Grafana managed alerts, you can create a rule with a classic condition or you can create a multi-dimensional rule.
Rule with classic condition
Multi dimensional rule
To generate a separate alert for each series, create a multi-dimensional rule. Use Math
, , or Resample
expressions to create a multi-dimensional rule. For example:
- Add a
Reduce
expression for each query to aggregate values in the selected time range into a single value. (Not needed for ). - Add a
Math
expression with the condition for the rule. Not needed in case a query or a reduce expression already returns 0 if rule should not fire, or a positive number if it should fire. Some examples:$B > 70
if it should fire in case value of B query/expression is more than 70.$B < $C * 100
in case it should fire if value of B is less than value of C multiplied by 100. If queries being compared have multiple series in their results, series from different queries are matched if they have the same labels or one is a subset of the other.
Note: Grafana does not support alert queries with template variables. More information is available at https://community.grafana.com/t/template-variables-are-not-supported-in-alert-queries-while-setting-up-alert/2514.
Rule with classic condition
No data and error handling
Configure alerting behavior in the absence of data using information in the following tables.
Error or timeout option | Description |
---|---|
Alerting | Set alert rule state to Alerting . From Grafana 8.5, the alert rule waits for the entire duration for which the condition is true before firing. |
OK | Set alert rule state to Normal |
Error | Create a new alert DatasourceError with the name and UID of the alert rule, and UID of the datasource that returned no data as labels. |