add wmi_service_info metric with display_name and pid labels (#516)

* add wmi_service_info metric
This commit is contained in:
Guillermo Sanchez Gavier
2020-05-15 13:13:25 +02:00
committed by GitHub
parent 54d94c261b
commit 99ed969bf7
2 changed files with 28 additions and 7 deletions

View File

@@ -3,6 +3,7 @@
package collector
import (
"strconv"
"strings"
"github.com/StackExchange/wmi"
@@ -24,9 +25,10 @@ var (
// A serviceCollector is a Prometheus collector for WMI Win32_Service metrics
type serviceCollector struct {
State *prometheus.Desc
StartMode *prometheus.Desc
Status *prometheus.Desc
Information *prometheus.Desc
State *prometheus.Desc
StartMode *prometheus.Desc
Status *prometheus.Desc
queryWhereClause string
}
@@ -40,6 +42,12 @@ func NewserviceCollector() (Collector, error) {
}
return &serviceCollector{
Information: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "info"),
"A metric with a constant '1' value labeled with service information",
[]string{"name", "display_name", "process_id"},
nil,
),
State: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "state"),
"The state of the service (State)",
@@ -75,10 +83,12 @@ func (c *serviceCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metr
// Win32_Service docs:
// - https://msdn.microsoft.com/en-us/library/aa394418(v=vs.85).aspx
type Win32_Service struct {
Name string
State string
Status string
StartMode string
DisplayName string
Name string
ProcessId uint32
State string
Status string
StartMode string
}
var (
@@ -123,6 +133,16 @@ func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
}
for _, service := range dst {
pid := strconv.FormatUint(uint64(service.ProcessId), 10)
ch <- prometheus.MustNewConstMetric(
c.Information,
prometheus.GaugeValue,
1.0,
strings.ToLower(service.Name),
service.DisplayName,
pid,
)
for _, state := range allStates {
isCurrentState := 0.0
if state == strings.ToLower(service.State) {

View File

@@ -20,6 +20,7 @@ Example: `--collector.service.services-where="Name='wmi_exporter'"`
Name | Description | Type | Labels
-----|-------------|------|-------
`wmi_service_info` | Contains service information in labels, constant 1 | gauge | name, display_name, process_id
`wmi_service_state` | The state of the service, 1 if the current state, 0 otherwise | gauge | name, state
`wmi_service_start_mode` | The start mode of the service, 1 if the current start mode, 0 otherwise | gauge | name, start_mode
`wmi_service_status` | The status of the service, 1 if the current status, 0 otherwise | gauge | name, status