MySQL Columns As Labels For Alerting

So Grafana 10 is out and I still need the same solution. I STILL need a column(string) in MySQL to be a label so I can do dynamic alerting. I’m giving this one last try (crossing my fingers) that there is an actual solution. I should be able to do the following:

SELECT Date, Disk_Usage1 AS “/” FROM hostsRH8.host

For the query from MySQL

Host {{labels.Hostname}} is having disk space issues

In the alert

However, the label still shows as Unknown. Hostname is a column in the MySQL table. How do you fix this???

image

It should also be noted that I still can’t select the Hostname in the query due to the following:

SELECT Date, Hostname, Disk_Usage1 AS “/” FROM hostsRH8.host

Failed to evaluate queries and expressions: input data must be a wide series but got type long (input refid)

Hi Jason! Have you tried this example here?

This option won’t work for MySQL

Hmm, it works for me in MySQL! Here is the data in the servers table:

MariaDB [example]> SELECT * FROM servers;
+----+---------+----------+--------+-----------------+
| id | domain  | chassis  | model  | oper_state_code |
+----+---------+----------+--------+-----------------+
|  1 | domain1 | chassis1 | model1 | degraded        |
|  2 | domain2 | chassis2 | model2 | degraded        |
+----+---------+----------+--------+-----------------+
2 rows in set (0.001 sec)

and screenshots of it working here:

Could you create some test data in a different table with the same schema and share it here?

@jasonmallory try change format from Table to Timeseries.

Also, use query builder and assign correct aliases for columns.
If / is value column then your SQL will look like

SELECT 
Date as time,
Host,
'/' as value
FROM ...

Okay I’m a little closer:

I removed the LIMIT 50 and got this:

I guess that there is no data and the expression engine gets confused by that and returns error

Okay I think I’m getting somewhere. I show this under the conditions:

At this point should I be able to do the following?

At this point should I be able to do the following?

You need to use $labels as per the example here.

1 Like

This?

This?

Yes! The documentation for that can be found here also :slight_smile:

1 Like

Holy crap! I’ve been looking for this for almost a year! Thank you! We have over 2,000 servers, services, devices and satellites we are monitoring for alerting!

Thanks a bunch you guys! This is a TREMENDOUS help!