mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-23 21:26:36 +00:00
feat (service): added support for service StartName
Signed-off-by: paologallinaharbur <paologallina1992@gmail.com>
This commit is contained in:
@@ -45,7 +45,7 @@ func NewserviceCollector() (Collector, error) {
|
|||||||
Information: prometheus.NewDesc(
|
Information: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "info"),
|
prometheus.BuildFQName(Namespace, subsystem, "info"),
|
||||||
"A metric with a constant '1' value labeled with service information",
|
"A metric with a constant '1' value labeled with service information",
|
||||||
[]string{"name", "display_name", "process_id"},
|
[]string{"name", "display_name", "process_id", "start_name"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
State: prometheus.NewDesc(
|
State: prometheus.NewDesc(
|
||||||
@@ -89,6 +89,7 @@ type Win32_Service struct {
|
|||||||
State string
|
State string
|
||||||
Status string
|
Status string
|
||||||
StartMode string
|
StartMode string
|
||||||
|
StartName *string
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -131,9 +132,13 @@ func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, service := range dst {
|
for _, service := range dst {
|
||||||
pid := strconv.FormatUint(uint64(service.ProcessId), 10)
|
pid := strconv.FormatUint(uint64(service.ProcessId), 10)
|
||||||
|
|
||||||
|
startName := ""
|
||||||
|
if service.StartName != nil {
|
||||||
|
startName = *service.StartName
|
||||||
|
}
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Information,
|
c.Information,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
@@ -141,6 +146,7 @@ func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
strings.ToLower(service.Name),
|
strings.ToLower(service.Name),
|
||||||
service.DisplayName,
|
service.DisplayName,
|
||||||
pid,
|
pid,
|
||||||
|
startName,
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, state := range allStates {
|
for _, state := range allStates {
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ Example: `--collector.service.services-where="Name='windows_exporter'"`
|
|||||||
|
|
||||||
Name | Description | Type | Labels
|
Name | Description | Type | Labels
|
||||||
-----|-------------|------|-------
|
-----|-------------|------|-------
|
||||||
`windows_service_info` | Contains service information in labels, constant 1 | gauge | name, display_name, process_id
|
`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_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_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
|
`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` and `status` labels, see below.
|
For the values of the `state`, `start_mode`, `status` and `run_as` labels, see below.
|
||||||
|
|
||||||
### States
|
### States
|
||||||
|
|
||||||
@@ -66,6 +66,13 @@ A service can have any of the following statuses:
|
|||||||
|
|
||||||
Note that there is some overlap with service state.
|
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
|
### Example metric
|
||||||
Lists the services that have a 'disabled' start mode.
|
Lists the services that have a 'disabled' start mode.
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user