Files
windows_exporter/docs/collector.service.md
T

151 lines
6.8 KiB
Markdown

# service collector
The service collector exposes metrics about Windows Services
| | |
|---------------------|-----------|
| Metric name prefix | `service` |
| Classes | none |
| Enabled by default? | Yes |
## Flags
### `--collector.service.include`
Regular expression of service to include. Service name (not the display name!) must both
match `include` and not match `exclude` to be included.
Recommended to keep down number of returned metrics. Default: `.+`
### `--collector.service.exclude`
Regular expression of service to exclude. Service name (not the display name!) must both
match `include` and not match `exclude` to be included.
Recommended to keep down number of returned metrics. Default: empty
### `--collector.service.start-mode-include`
Comma separated list of service start modes to include.
Possible values: auto, boot, manual, disabled, system.
Recommended to keep down number of returned metrics. Default: `auto,boot,manual,disabled,system`
## Configuration cache
The service configuration (display name, start mode, path and account, used by
`windows_service_info` and `windows_service_start_mode`) is cached between scrapes.
The collector watches the registry key `HKLM\SYSTEM\CurrentControlSet\Services`. When a
service's own key changes, for example after `sc config`, a change in the Services console
or a reinstall, its configuration is queried again on the next scrape. All configurations
are queried again at the latest every 10 minutes. The service state and process are queried
on every scrape.
## Metrics
| Name | Description | Type | Labels |
|------------------------------|-----------------------------------------------------------------------------------------------|-------|---------------------------------------|
| `windows_service_info` | Contains service information run as user in labels, constant 1 | gauge | service, display_name, run_as, path_name |
| `windows_service_start_mode` | The start mode of the service, 1 if the current start mode, 0 otherwise | gauge | service, start_mode |
| `windows_service_state` | The state of the service, 1 if the current state, 0 otherwise | gauge | service, state |
| `windows_service_process` | Process of started service. The value is the creation time of the process as a Unix timestamp | gauge | service, process_id |
### States
A service can be in the following states:
- `stopped`
- `start pending`
- `stop pending`
- `running`
- `continue pending`
- `pause pending`
- `paused`
### Start modes
A service can have the following start modes:
- `boot`
- `system`
- `auto`
- `manual`
- `disabled`
Note that there is some overlap with service state.
### Run As
Account name under which a service runs. Depending on the service type, the account name may be in the form of "DomainName\Username" or UPN format ("Username@DomainName").
### Example metric
```
# HELP windows_service_info A metric with a constant '1' value labeled with service information
# TYPE windows_service_info gauge
windows_service_info{display_name="Declared Configuration(DC) service",service="dcsvc",path_name="C:\\WINDOWS\\system32\\svchost.exe -k netsvcs -p",run_as="LocalSystem"} 1
windows_service_info{display_name="Designs",service="Themes",path_name="C:\\WINDOWS\\System32\\svchost.exe -k netsvcs -p",run_as="LocalSystem"} 1
# HELP windows_service_process Process of started service. The value is the creation time of the process as a unix timestamp.
# TYPE windows_service_process gauge
windows_service_process{service="Themes",process_id="2856"} 1.7244891e+09
# HELP windows_service_start_mode The start mode of the service (StartMode)
# TYPE windows_service_start_mode gauge
windows_service_start_mode{service="Themes",start_mode="auto"} 1
windows_service_start_mode{service="Themes",start_mode="boot"} 0
windows_service_start_mode{service="Themes",start_mode="disabled"} 0
windows_service_start_mode{service="Themes",start_mode="manual"} 0
windows_service_start_mode{service="Themes",start_mode="system"} 0
windows_service_start_mode{service="dcsvc",start_mode="auto"} 0
windows_service_start_mode{service="dcsvc",start_mode="boot"} 0
windows_service_start_mode{service="dcsvc",start_mode="disabled"} 0
windows_service_start_mode{service="dcsvc",start_mode="manual"} 1
windows_service_start_mode{service="dcsvc",start_mode="system"} 0
# HELP windows_service_state The state of the service (State)
# TYPE windows_service_state gauge
windows_service_state{service="Themes",state="continue pending"} 0
windows_service_state{service="Themes",state="pause pending"} 0
windows_service_state{service="Themes",state="paused"} 0
windows_service_state{service="Themes",state="running"} 1
windows_service_state{service="Themes",state="start pending"} 0
windows_service_state{service="Themes",state="stop pending"} 0
windows_service_state{service="Themes",state="stopped"} 0
windows_service_state{service="dcsvc",state="continue pending"} 0
windows_service_state{service="dcsvc",state="pause pending"} 0
windows_service_state{service="dcsvc",state="paused"} 0
windows_service_state{service="dcsvc",state="running"} 0
windows_service_state{service="dcsvc",state="start pending"} 0
windows_service_state{service="dcsvc",state="stop pending"} 0
windows_service_state{service="dcsvc",state="stopped"} 1
```
## Useful queries
Counts the number of Microsoft SQL Server/Agent Processes
```
count(windows_service_state{service=~"(sqlserveragent|mssqlserver)",state="running"})
```
## Alerting examples
**prometheus.rules**
```yaml
groups:
- name: Microsoft SQL Server Alerts
rules:
# Sends an alert when the 'sqlserveragent' service is not in the running state for 3 minutes.
- alert: SQL Server Agent DOWN
expr: windows_service_state{instance="SQL",service="sqlserveragent",state="running"} == 0
for: 3m
labels:
severity: high
annotations:
summary: "Service {{ $labels.service }} down"
description: "Service {{ $labels.service }} on instance {{ $labels.instance }} has been down for more than 3 minutes."
# Sends an alert when the 'mssqlserver' service is not in the running state for 3 minutes.
- alert: SQL Server DOWN
expr: windows_service_state{instance="SQL",service="mssqlserver",state="running"} == 0
for: 3m
labels:
severity: high
annotations:
summary: "Service {{ $labels.service }} down"
description: "Service {{ $labels.service }} on instance {{ $labels.instance }} has been down for more than 3 minutes."
```
In this example, `instance` is the target label of the host. So each alert will be processed per host, which is then used in the alert description.