How to alert on Windows Service State

I have searched through previous forum posts related to this topic but have not been able to find an answer.

Goal: To be able to fire off an alert when particular windows services are down

Setup: We use Grafana Cloud Advanced bundle. We are running Alloy on all of our Windows servers and use RemoteCFG within Grafana. I do have “service” as an enabled collector.

This is the PromQL that I wrote for the alert to start:

windows_service_status{instance=“servernamegoeshere”, name=~" service#1|service#2|service#3|service#4|service#5", status=“ok”, environment!=“Production”}

The above query successfully split up my services and is alerting on each of them individually under 1 alert. The issue I’m having is even when I stop the service it’s still showing as “status=ok” so the alarm does not trigger.

image

I ran the command above in Powershell on the server and noticed even though the state is “stopped” it still shows the status as “ok”. I’m guessing this is my issue…

Through googling I tried to run a query of "windows_service_state{instance=“servernamegoeshere”, name=“service#1”} – but it comes back with no data. My goal was to have it alert whenever state!=running, which would alert on any status other than running (I’d think).

Does Alloy not have the ability to do “windows_service_state”? If not, are there any other recommendations on how to set this up using Alloy? Figured I’d check here before opening up a ticket with Grafana.

Thanks in advance!

I believe I’ve answered my first question by finding the Windows Integration documentation on Grafana’s site. Looks like it only includes the metric “windows_service_status”, and then looking at the Windows exporter documentation… it includes “windows_service_state”.

My second question still stands, does anyone have a suggestion on how I can accomplish the my goal using Alloy? Thanks again :slight_smile: