Alert when service is down

I would like to create an alert if a Windows service is down. I have the following query I’m getting via MS SQL:
select ServiceName, Status, TimeUTC as 'time' from ServicesStatus
where Status returns either 0 (down) or 1 (up).

The furthest I managed to get is to trigger an alert on avg() if it goes below 1, but couldn’t figure out how to expose in the alert message which ServiceName has a Status value of 0.

Ideally, I would like to build an alert message template like this: “Service {ServiceName} is down for the last 5 minutes”.

Is that possible with Grafana?

What is your Grafana version?

By the way, have you tried to use windows-exporter and Prometheus? Maybe it’s a better solution

Version 8.2.5.
I’m not using Prometheus, I have a .NET based backend which is populating the SQL Server database.


If you use NGAlerts, you can use labels. More information is here - Annotations and labels for alerting rules | Grafana Labs

In your case, it should be something like this:
Service {{ $labels.ServiceName }} is down for the last 5 minutes

I do use NGAlerts and its working now as you suggested.
Took me a while though to realize that classic conditions are not working with message variables, so I used a math expression instead ($B < 1).


Maybe this is answered somewhere else, but happen to know how to variable-ize the status for the message box?

Service {{ $labels.ServiceName }} is {{ status }} for the last 5 minutes

At first, you should open your own topic for your question

Please show us your query and provide with more information about alert settings