TechBuzzPro

How to Collect Windows Service Metrics in Prometheus

· 4 min read · Windows & PC

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To collect data about a Windows service in Prometheus, you must run the windows_exporter binary on the target machine. This exporter exposes system and service metrics in a format that Prometheus can scrape directly via HTTP. Without this intermediary agent, Prometheus cannot natively read Windows internal counters.

What You'll Need

  • A Windows server or workstation running a supported version (Windows Server 2016/2019/2022 or Windows 10/11).
  • Administrative privileges on the target machine to install services and open firewall ports.
  • Access to a Prometheus server instance configured to scrape endpoints.
  • The latest release of windows_exporter from the official GitHub repository.

Step-by-Step

  1. Download the Exporter: Navigate to the official windows_exporter GitHub releases page. Download the ZIP file corresponding to your architecture (typically amd64). Extract the contents to a permanent directory, such as C:\Program Files\windows_exporter, to prevent accidental deletion during updates.
  2. Create a Dedicated User: For security best practices, do not run the exporter under the Administrator account. Create a local user account (e.g., prometheus_svc) with a strong password. This user will be used to run the Windows service later.
  3. Configure Permissions: The exporter needs specific permissions to read performance counters. Open PowerShell as Administrator and grant the new user permission to access WMI and performance counters. Run the command: Add-WmiPermission -Namespace "root\cimv2" -AccountName "prometheus_svc" -AccessMask ReadSecurity -PrincipalType User. Note that menu labels may differ slightly by Windows version.
  4. Install as a Windows Service: Use the built-in utility to install the exporter as a background service. In PowerShell, navigate to your installation folder and run: .\windows_exporter.exe --collector.service.enabled --web.listen-address=:9182 install. Then start it using: .\windows_exporter.exe --collector.service.enabled --web.listen-address=:9182 start.
  5. Verify Local Access: Open a web browser on the Windows machine and navigate to http://localhost:9182/metrics. You should see a stream of text-based metrics starting with # HELP and # TYPE. If you see an error, check the Windows Event Viewer under "Application" for logs related to windows_exporter.
  6. Configure Firewall Rules: Allow inbound traffic on port 9182 so your Prometheus server can reach the exporter. Open PowerShell as Administrator and run: New-NetFirewallRule -DisplayName "Prometheus Windows Exporter" -Direction Inbound -LocalPort 9182 -Protocol TCP -Action Allow.
  7. Update Prometheus Configuration: On your Prometheus server, edit the prometheus.yml file. Add a new job under the scrape_configs section:
      - job_name: 'windows_services'
        static_configs:
          - targets: ['windows-host-ip:9182']
            labels:
              instance: 'my-windows-server'
    Restart the Prometheus service to apply changes.
  8. Validate Data Collection: Go to the Prometheus UI (usually http://localhost:9090). Click "Status" then "Targets". Your new Windows target should show as "UP". Query for service status using: windows_service_state{name="Spooler"} to verify specific service data is flowing.

Common Mistakes

One frequent error is failing to grant WMI permissions to the non-admin user, resulting in empty metrics or authentication errors. Another common issue is forgetting to open the Windows Firewall, which causes the Prometheus target to appear as "DOWN" due to connection timeouts. Users also often neglect to use the --collector.service.enabled flag, meaning only general CPU/memory metrics are collected, but no specific service states.

Tips

Use the --collector.service.where flag to filter out noisy services. For example, adding --collector.service.where="State='Running'" reduces metric cardinality and storage costs. Always monitor the windows_exporter_build_info metric to ensure you are running the latest stable version. Consider using Windows Task Scheduler to automatically restart the exporter if it crashes unexpectedly.

Troubleshooting

If the target shows as "DOWN", first verify network connectivity using Test-NetConnection windows-host-ip -Port 9182 from the Prometheus server. Check if the windows_exporter service is actually running in Windows Services management console. Review the Windows Event Logs for detailed error messages. If metrics are missing specific services, ensure the --collector.service.enabled flag was present during installation. Restarting the exporter service often resolves temporary counter lockups.

Frequently Asked Questions

Can I use this on Windows 10?

Yes, the exporter supports Windows 10 and 11, provided they are joined to a domain or configured with local accounts correctly.

Does this impact system performance?

The impact is negligible. It uses minimal CPU and memory, typically less than 50MB RAM and low single-digit CPU percentages.

How do I secure the endpoint?

Use Windows Authentication or place the exporter behind a reverse proxy like Nginx with basic auth or TLS termination.

Why are some services missing from metrics?

Services running under SYSTEM or LocalService accounts might require additional WMI permissions granted to your exporter user.

Can I collect custom application metrics?

This exporter focuses on OS-level services. For custom app metrics, consider using the Pushgateway or writing a custom exporter.