I am using Grafana v10.1.0 through Docker.
I have a dashboard that uses a variable to define the list of hostnames I’m interested in displaying data for. This works well as we add new machines we can just update this variable.
I’d like to re-use that variable in my alerts. I’d also be okay if I just define the variable again in the Alert page. Neither seem to be things one can do with alerts.
Is there a mechanism of any kind to supply a variable to an Alert so I don’t have to edit a bunch of alert queries?
Hi! No dashboard variables are not supported in Grafana Alerting as their purpose is to support filtering data when viewing panels. You’ll want to use multi-dimensional alerting instead which means there is no need to use dashboard variables. You can find more information on that here:
As July 2024, the “Grafana Alerting vs Legacy dashboard alerting” link is broken.
Looks that it was removed.
You can read about Grafana Alerting vs Legacy Alerting here
And, to elaborate on George’s answer, the reason why there is no need to use variables in Grafana Alerting is that an alert rule can generate multiple alert instances - one for each time series produced by the alert rule’s query. This means you can have a single alert rule that automatically handles multiple dimensions, such as different hostnames
or other labels in your data.
In practical terms, when you create a multi-dimensional alert rule, the query can return multiple time series, each corresponding to different dimensions. For example, if your query includes a hostname
label, Grafana will evaluate the alert condition separately for each hostname. This eliminates the need for manually creating separate alerts for each hostname.
Finally, you can use an Expression (e.g., a threshold expression) to check if any of the series match the condition. Expressions allow you to perform further calculations or transformations on your query results, providing greater flexibility in defining your alert conditions.
1 Like