Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service: Breaking split service collector into two separate collectors #1563

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Name | Description | Enabled by default
[remote_fx](docs/collector.remote_fx.md) | RemoteFX protocol (RDP) metrics |
[scheduled_task](docs/collector.scheduled_task.md) | Scheduled Tasks metrics |
[service](docs/collector.service.md) | Service state metrics | ✓
[service_info](docs/collector.service_info.md) | Service info metrics | ✓
[smb](docs/collector.smb.md) | SMB Server |
[smbclient](docs/collector.smbclient.md) | SMB Client |
[smtp](docs/collector.smtp.md) | IIS SMTP Server |
Expand Down
113 changes: 7 additions & 106 deletions docs/collector.service.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,121 +2,22 @@

The service collector exposes metrics about Windows Services

The collector exists in 2 different version. Version 1 is using WMI to query all services and is able to provide additional
information. Version 2 is a more efficient solution by directly connecting to the service manager, but is not able to
provide additional information like `run_as` or start configuration

## Flags

### `--collector.service.services-where`

A WMI filter on which services to include. Recommended to keep down number of returned metrics.

Example: `--collector.service.services-where="Name='windows_exporter'"`

Example config win_exporter.yml for multiple services: `services-where: Name='SQLServer' OR Name='Couchbase' OR Name='Spooler' OR Name='ActiveMQ'`

### `--collector.service.use-api`

Uses API calls instead of WMI for performance optimization. **Note** the previous flag (`--collector.service.services-where`) won't have any effect on this mode.

### `--collector.service.v2`

Version 2 of the service collector. Is using API calls for performance optimization. **Note** the previous flag (`--collector.service.services-where`) won't have any effect on this mode.
For additional performance reasons, it doesn't provide any additional information like `run_as` or start configuration.

# collector V1

|||
-|-
Metric name prefix | `service`
Classes | [`Win32_Service`](https://msdn.microsoft.com/en-us/library/aa394418(v=vs.85).aspx)
Enabled by default? | Yes

## Metrics

Name | Description | Type | Labels
-----|-------------|------|-------
`windows_service_info` | Contains service information in labels, constant 1 | gauge | name, display_name, process_id, run_as
`windows_service_state` | The state of the service, 1 if the current state, 0 otherwise | gauge | name, state
`windows_service_start_mode` | The start mode of the service, 1 if the current start mode, 0 otherwise | gauge | name, start_mode
`windows_service_status` | The status of the service, 1 if the current status, 0 otherwise | gauge | name, status

For the values of the `state`, `start_mode`, `status` and `run_as` labels, see below.

### States

A service can be in the following states:
- `stopped`
- `start pending`
- `stop pending`
- `running`
- `continue pending`
- `pause pending`
- `paused`
- `unknown`

### Start modes

A service can have the following start modes:
- `boot`
- `system`
- `auto`
- `manual`
- `disabled`

### Status (not available in API mode)

A service can have any of the following statuses:
- `ok`
- `error`
- `degraded`
- `unknown`
- `pred fail`
- `starting`
- `stopping`
- `service`
- `stressed`
- `nonrecover`
- `no contact`
- `lost comm`

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").

It corresponds to the `StartName` attribute of the `Win32_Service` class.
`StartName` attribute can be NULL and in such case the label is reported as an empty string. Notice that if the attribute is NULL the service is logged on as the `LocalSystem` account or, for kernel or system-level drive, it runs with a default object name created by the I/O system based on the service name, for example, DWDOM\Admin.

### Example metric
Lists the services that have a 'disabled' start mode.
```
windows_service_start_mode{exported_name=~"(mssqlserver|sqlserveragent)",start_mode="disabled"}
```

## Useful queries
Counts the number of Microsoft SQL Server/Agent Processes
```
count(windows_service_state{exported_name=~"(sqlserveragent|mssqlserver)",state="running"})
```

# collector V2


|||
-|-
Metric name prefix | `service`
Classes | none
Enabled by default? | No

## Flags

None

## Metrics

Name | Description | Type | Labels
-----|-------------|------|-------
`windows_service_state` | The state of the service, 1 if the current state, 0 otherwise | gauge | name, display_name, state
| Name | Description | Type | Labels |
|------------------------------|----------------------------------------------------------------------|-------|---------------------------|
| `windows_service_state` | The state of the service, 1 if the current state, 0 otherwise | gauge | name, display_name, state |
| `windows_service_process_id` | Contains the process_id of the service process in labels, constant 1 | gauge | name, process_id |

### States

Expand Down
65 changes: 65 additions & 0 deletions docs/collector.service_info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# service_info collector

The service collector exposes information as metrics about Windows Services

| | |
|---------------------|----------------|
| Metric name prefix | `service_info` |
| Classes | - |
| Enabled by default? | Yes |

## Flags

None

## Metrics

| Name | Description | Type | Labels |
|-----------------------------------|-------------------------------------------------------------------------|-------|-------------------------|
| `windows_service_info` | Contains service information run as user in labels, constant 1 | gauge | name, path_name, run_as |
| `windows_service_info_start_mode` | The start mode of the service, 1 if the current start mode, 0 otherwise | gauge | name, start_mode |

For the values of the `start_mode`, `status` and `run_as` labels, see below.


### 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{name="AJRouter",path_name="C:\\WINDOWS\\system32\\svchost.exe -k LocalServiceNetworkRestricted -p",run_as="NT AUTHORITY\\LocalService"} 1
windows_service_info{name="ALG",path_name="C:\\WINDOWS\\System32\\alg.exe",run_as="NT AUTHORITY\\LocalService"} 1
# HELP windows_service_info_start_mode The start mode of the service (StartMode)
# TYPE windows_service_info_start_mode gauge
windows_service_info_start_mode{name="AGSService",start_mode="auto"} 0
windows_service_info_start_mode{name="AGSService",start_mode="boot"} 0
windows_service_info_start_mode{name="AGSService",start_mode="disabled"} 1
windows_service_info_start_mode{name="AGSService",start_mode="manual"} 0
windows_service_info_start_mode{name="AGSService",start_mode="system"} 0
windows_service_info_start_mode{name="AJRouter",start_mode="auto"} 0
windows_service_info_start_mode{name="AJRouter",start_mode="boot"} 0
windows_service_info_start_mode{name="AJRouter",start_mode="disabled"} 0
windows_service_info_start_mode{name="AJRouter",start_mode="manual"} 1
windows_service_info_start_mode{name="AJRouter",start_mode="system"} 0
windows_service_info_start_mode{name="ALG",start_mode="auto"} 0
windows_service_info_start_mode{name="ALG",start_mode="boot"} 0
windows_service_info_start_mode{name="ALG",start_mode="disabled"} 0
windows_service_info_start_mode{name="ALG",start_mode="manual"} 1
windows_service_info_start_mode{name="ALG",start_mode="system"} 0
```
2 changes: 2 additions & 0 deletions pkg/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
"github.com/prometheus-community/windows_exporter/pkg/collector/remote_fx"
"github.com/prometheus-community/windows_exporter/pkg/collector/scheduled_task"
"github.com/prometheus-community/windows_exporter/pkg/collector/service"
"github.com/prometheus-community/windows_exporter/pkg/collector/service_info"
"github.com/prometheus-community/windows_exporter/pkg/collector/smb"
"github.com/prometheus-community/windows_exporter/pkg/collector/smbclient"
"github.com/prometheus-community/windows_exporter/pkg/collector/smtp"
Expand Down Expand Up @@ -135,6 +136,7 @@ func NewWithConfig(logger log.Logger, config Config) Collectors {
collectors[remote_fx.Name] = remote_fx.New(logger, &config.RemoteFx)
collectors[scheduled_task.Name] = scheduled_task.New(logger, &config.ScheduledTask)
collectors[service.Name] = service.New(logger, &config.Service)
collectors[service_info.Name] = service_info.New(logger, &config.ServiceInfo)
collectors[smb.Name] = smb.New(logger, &config.SMB)
collectors[smbclient.Name] = smbclient.New(logger, &config.SMBClient)
collectors[smtp.Name] = smtp.New(logger, &config.SMTP)
Expand Down
3 changes: 3 additions & 0 deletions pkg/collector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/prometheus-community/windows_exporter/pkg/collector/remote_fx"
"github.com/prometheus-community/windows_exporter/pkg/collector/scheduled_task"
"github.com/prometheus-community/windows_exporter/pkg/collector/service"
"github.com/prometheus-community/windows_exporter/pkg/collector/service_info"
"github.com/prometheus-community/windows_exporter/pkg/collector/smb"
"github.com/prometheus-community/windows_exporter/pkg/collector/smbclient"
"github.com/prometheus-community/windows_exporter/pkg/collector/smtp"
Expand Down Expand Up @@ -104,6 +105,7 @@ type Config struct {
RemoteFx remote_fx.Config `yaml:"remote_fx"`
ScheduledTask scheduled_task.Config `yaml:"scheduled_task"`
Service service.Config `yaml:"service"`
ServiceInfo service_info.Config `yaml:"service_info"`
SMB smb.Config `yaml:"smb"`
SMBClient smbclient.Config `yaml:"smbclient"` //nolint:tagliatelle
SMTP smtp.Config `yaml:"smtp"`
Expand Down Expand Up @@ -166,6 +168,7 @@ var ConfigDefaults = Config{
RemoteFx: remote_fx.ConfigDefaults,
ScheduledTask: scheduled_task.ConfigDefaults,
Service: service.ConfigDefaults,
ServiceInfo: service_info.ConfigDefaults,
SMB: smb.ConfigDefaults,
SMBClient: smbclient.ConfigDefaults,
SMTP: smtp.ConfigDefaults,
Expand Down
2 changes: 2 additions & 0 deletions pkg/collector/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/prometheus-community/windows_exporter/pkg/collector/remote_fx"
"github.com/prometheus-community/windows_exporter/pkg/collector/scheduled_task"
"github.com/prometheus-community/windows_exporter/pkg/collector/service"
"github.com/prometheus-community/windows_exporter/pkg/collector/service_info"
"github.com/prometheus-community/windows_exporter/pkg/collector/smb"
"github.com/prometheus-community/windows_exporter/pkg/collector/smbclient"
"github.com/prometheus-community/windows_exporter/pkg/collector/smtp"
Expand Down Expand Up @@ -105,6 +106,7 @@ var BuildersWithFlags = map[string]BuilderWithFlags[Collector]{
remote_fx.Name: NewBuilderWithFlags(remote_fx.NewWithFlags),
scheduled_task.Name: NewBuilderWithFlags(scheduled_task.NewWithFlags),
service.Name: NewBuilderWithFlags(service.NewWithFlags),
service_info.Name: NewBuilderWithFlags(service_info.NewWithFlags),
smb.Name: NewBuilderWithFlags(smb.NewWithFlags),
smbclient.Name: NewBuilderWithFlags(smbclient.NewWithFlags),
smtp.Name: NewBuilderWithFlags(smtp.NewWithFlags),
Expand Down
3 changes: 3 additions & 0 deletions pkg/collector/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,11 @@ func (coll *Prometheus) execute(name string, c Collector, ctx *types.ScrapeConte

if err != nil {
_ = level.Error(coll.logger).Log("msg", fmt.Sprintf("collector %s failed after %fs", name, duration), "err", err)

return failed
}

_ = level.Debug(coll.logger).Log("msg", fmt.Sprintf("collector %s succeeded after %fs.", name, duration))

return success
}
Loading