There have not been a lot of easy-to-follow examples using Flux for creating Grafana Alerts, so with the kind permission of the Grafana Labs team, I put together 5 examples that use Flux queries which can be used with Grafana Alerting. Hope this helps others who might be just getting started with Flux and Grafana Alerting.
Please reply here if there is any feedback or questions.
Awesome! One thing I can’t get to work is alerts for future values, how would you do that? I have a set of forecasted values and would like to alert based on values exceeding the threshold in there. Alerts don’t seem to allow values into the future.
I have a question. I was able to set up some alerts with influxv2 and Grafana as you demonstrated.
Something I am having trouble with is configuring the notification message. I’d like to add a template annotation and label with variables outside of the alert like shown in this tutorial:
I am not sure how to bring in other variables into the annotation.
For example, my alert flux query is for variable “disp_st” in measurement “display” but when the alert goes off I want to the message to display another variable from another measurement.
Are you aware of how to do this?
I believe Example 2 would be a good starting point since the alert message template is built from two different buckets, each with different measurements. I no longer have that test data around, so I cannot do a quick test at the moment, but yes, I believe it would / should be possible. Will try to get a better answer later.
Hi Grant! Did you get a chance to look into this? I am still working on getting this to work.
I added two queries to my alert. A grabs a display state and B grabs a device serial number that I need in the alert. I am still not able to get the serial number to print out on the alert.
I added this to the custom annotation Serial Number = {{ $values.B.Value }} but I get [no value].
I am not sure what information you need from me to help trouble shoot this. Thank you so much!
My main two issues when I do this above is it stops displaying other information from query in “A.”
And displays this:
Serial Number = {{printf $values.B.sn }} instead of the actual number.