mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-25 14:16:36 +00:00
Add status metric for service-collector
This commit is contained in:
@@ -27,6 +27,7 @@ var (
|
|||||||
type serviceCollector struct {
|
type serviceCollector struct {
|
||||||
State *prometheus.Desc
|
State *prometheus.Desc
|
||||||
StartMode *prometheus.Desc
|
StartMode *prometheus.Desc
|
||||||
|
Status *prometheus.Desc
|
||||||
|
|
||||||
queryWhereClause string
|
queryWhereClause string
|
||||||
}
|
}
|
||||||
@@ -56,6 +57,12 @@ func NewserviceCollector() (Collector, error) {
|
|||||||
[]string{"name", "start_mode"},
|
[]string{"name", "start_mode"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
Status: prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(Namespace, subsystem, "status"),
|
||||||
|
"The status of the service (Status)",
|
||||||
|
[]string{"name", "status"},
|
||||||
|
nil,
|
||||||
|
),
|
||||||
queryWhereClause: wc.String(),
|
queryWhereClause: wc.String(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -73,6 +80,7 @@ func (c *serviceCollector) Collect(ch chan<- prometheus.Metric) error {
|
|||||||
type Win32_Service struct {
|
type Win32_Service struct {
|
||||||
Name string
|
Name string
|
||||||
State string
|
State string
|
||||||
|
Status string
|
||||||
StartMode string
|
StartMode string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +102,20 @@ var (
|
|||||||
"manual",
|
"manual",
|
||||||
"disabled",
|
"disabled",
|
||||||
}
|
}
|
||||||
|
allStatuses = []string{
|
||||||
|
"ok",
|
||||||
|
"error",
|
||||||
|
"degraded",
|
||||||
|
"unknown",
|
||||||
|
"pred fail",
|
||||||
|
"starting",
|
||||||
|
"stopping",
|
||||||
|
"service",
|
||||||
|
"stressed",
|
||||||
|
"nonrecover",
|
||||||
|
"no contact",
|
||||||
|
"lost comm",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
@@ -131,6 +153,20 @@ func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
startMode,
|
startMode,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, status := range allStatuses {
|
||||||
|
isCurrentStatus := 0.0
|
||||||
|
if status == strings.ToLower(service.Status) {
|
||||||
|
isCurrentStatus = 1.0
|
||||||
|
}
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.Status,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
isCurrentStatus,
|
||||||
|
strings.ToLower(service.Name),
|
||||||
|
status,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user