How to send Windows service data to Prometheus

Prometheus does not natively read Windows services. You need an intermediary tool called the Windows Exporter that runs on your Windows machine, watches your services, and exposes their status as metrics that Prometheus can scrape. The Windows Exporter collects data about whether services are running, when they started, and how many restarts they have had, then serves that data on a local port that Prometheus polls at regular intervals.

The process has three parts: install the Windows Exporter on the machine running your services, configure Prometheus to scrape it, and then query the metrics you collected. Most of the setup happens once, and then the data flows automatically.

Key Takeaways

  • Windows Exporter is a small program that translates Windows service status into metrics Prometheus understands, and you run it as a Windows service itself.
  • You download Windows Exporter as a single executable, run it with administrator privileges, and it listens on port 9182 by default.
  • In your Prometheus configuration file, you add a scrape job that points to the Windows machine's IP address and port 9182 to collect the metrics.
  • The main service metrics are windows_service_state (whether the service is running) and windows_service_start_mode (whether it starts automatically or manually).

Download and install Windows Exporter

Go to the Windows Exporter releases page on GitHub at github.com/prometheus-community/windows_exporter/releases. Download the latest MSI installer for your system architecture — most modern Windows machines are 64-bit, so download the file named something like windows_exporter-0.x.x-amd64.msi. If you are unsure whether your machine is 32-bit or 64-bit, open Settings, go to System, and look at System Type.

Run the MSI installer with administrator privileges. Right-click the file and select "Run as administrator". The installer will ask you where to install the exporter and what port to use. The default port is 9182 — keep this unless you have a specific reason to change it. The installer will also register Windows Exporter as a Windows service so it starts automatically when the machine boots.

After installation completes, open a command prompt and run netstat -an | find "9182" to confirm the exporter is listening. You should see a line showing the port is in LISTEN state. If you see nothing, the exporter did not start. Open Services (press Windows+R, type services.msc, and press Enter), find "Prometheus Windows Exporter" in the list, right-click it, and select Start.

Verify the exporter is collecting service data

Open a web browser on the Windows machine and go to http://localhost:9182/metrics. You will see a long list of metrics in plain text. Scroll down and look for lines that start with windows_service_. These are the service metrics. Each service on the machine will have entries showing its state, start mode, and other details.

If you see metrics but they look wrong — for example, all services show state 0 or 4 — the exporter is working but may need configuration. By default, Windows Exporter collects metrics for all services. If you want to collect data only for specific services, you can configure that, but for most setups the default is fine.

If you see no metrics at all, or the page does not load, the exporter is not running. Go back to Services, confirm the Prometheus Windows Exporter service is in the Running state, and check that no firewall rule is blocking port 9182 on the local machine.

Add the Windows machine to your Prometheus configuration

On the machine running Prometheus, open the Prometheus configuration file. This is usually at C:\Program Files\Prometheus\prometheus.yml on Windows or /etc/prometheus/prometheus.yml on Linux. Find the scrape_configs section. It will look like this:

scrape_configs:   - job_name: 'prometheus'     static_configs:       - targets: ['localhost:9090']

Add a new job for the Windows machine. Replace 192.168.1.100 with the actual IP address of the Windows machine running the exporter:

scrape_configs:   - job_name: 'prometheus'     static_configs:       - targets: ['localhost:9090']   - job_name: 'windows-services'     static_configs:       - targets: ['192.168.1.100:9182']

Save the file. Restart Prometheus. On Windows, open Services, find Prometheus, right-click it, and select Restart. On Linux, run sudo systemctl restart prometheus. Prometheus will now scrape the Windows machine every 15 seconds by default.

Query service metrics in Prometheus

Open the Prometheus web interface, usually at http://localhost:9090. Click the Graph tab. In the query box, type windows_service_state and press Enter. You will see a list of all services on the Windows machine with their current state. A value of 4 means the service is running. A value of 1 means it is stopped.

To see only a specific service, use a query like windows_service_state{name="YourServiceName"}. Replace YourServiceName with the actual Windows service name — for example, windows_service_state{name="MSSQLSERVER"} for SQL Server. You can find the exact service name by opening Services on the Windows machine and looking at the Name column.

To alert when a service stops unexpectedly, you can create an alert rule. In your Prometheus configuration, add a rule file and define an alert like this: alert: ServiceDown when windows_service_state{name="YourServiceName"} != 4 for 5m. This will fire an alert if the service is not in state 4 (running) for five minutes or more.

Troubleshoot common collection problems

If Prometheus shows no data for the Windows machine, first check that the Windows Exporter is running. On the Windows machine, open Services and look for "Prometheus Windows Exporter". If it is not running, right-click it and select Start. If it stops again after a few seconds, there is likely an error in the exporter configuration or a port conflict.

If the exporter is running but Prometheus still shows no data, check the network connection. On the Prometheus machine, open a command prompt and run telnet 192.168.1.100 9182 (replace the IP with your Windows machine's IP). If the connection times out or is refused, a firewall is blocking the port. On the Windows machine, open Windows Defender Firewall, click "Allow an app through firewall", and add the Windows Exporter executable to the allowed list.

If you see metrics but the service state is always 0 or always 4 regardless of the actual service status, the exporter may not have permission to read the service. Run the Windows Exporter installer again with administrator privileges and choose to repair the installation. If the problem persists, uninstall and reinstall the exporter.

Frequently Asked Questions

Can I collect data from services on multiple Windows machines?

Yes. Add a separate scrape job in your Prometheus configuration for each Windows machine, each with its own IP address and port 9182. You can also use a label to identify which machine each metric came from, making it easier to query and alert on specific machines.

What does windows_service_start_mode tell me?

This metric shows whether a service is set to start automatically, manually, or is disabled. A value of 2 means automatic, 3 means manual, and 4 means disabled. This is useful for detecting when someone has manually disabled a service that should be running.

How often does Prometheus collect the data?

By default, Prometheus scrapes each target every 15 seconds. You can change this by adding scrape_interval: 30s under the job configuration if you want less frequent collection, or scrape_interval: 5s for more frequent collection. More frequent scraping uses more CPU and storage.

Can I collect data about service restarts?

Yes. The metric windows_service_info includes a field called process_id that changes when a service restarts. By tracking changes to this value over time, you can detect unexpected restarts. Some monitoring tools build this logic into their alerting rules automatically.

What if the Windows machine is behind a firewall or on a different network?

Prometheus must be able to reach the Windows machine on port 9182. If the machines are on different networks, you may need to open a firewall rule or use a VPN. If you cannot open the port directly, some teams use a reverse proxy or a Prometheus relay to forward metrics securely across network boundaries.