Use Dashboard Variables in Alerts

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! :wave: 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

Hi,

I have a similar set up where I have a generic host stats dashboard to cover basic things like load/disk/memory etc. With a couple hundred machines, the dashboard has to be filtered by a hostname variable.

I have alerting configured as above with an instance per hostname/metric. However, I’ve been trying to add image rendering to create more informative slack notifications. Since we are not able to specify variables, it just renders against the defaults for the dashboard and provides a completely unrelated graph along with the alert.

Without being able to specify variables I can’t use images in notifications at all. Or, I can only use them in more granular dashboards, but requires unlinking dashboards/panels in other rules that would create a broken image.

Is there any way to solve this now, a year since the last post?

Not that I am aware of.

Just to be sure I understand, your have configured multidimensional alerting on your machines, and when one of them goes into alerting, you can see which one (I.e. shows the hostname) in a Slack message. However, the graph / image which accompanies it does not reflect that single hostname? So the reader knows which machine (hostname) is alerting but the graph is a mess?

Yes, everything about the alert is correct in slack. For this specific case it’s disk usage. So, the hostname is correct and the specific disk

As you can see, the graph that is rendered is nowhere near the alert threshold, 90%.

The disk that it has rendered is for the default in the “hostname” variable on the dashboard

This is the graph that should be getting rendered, against the correct hostname for above


And you can see annotations on there from other hosts firing alerts

Which version of Grafana are you using? Can you share the query you created for the alert?

Running OSS@12.1.0

InfluxDB query

And grouping/notification settings