feat (service): added support for service StartName

Signed-off-by: paologallinaharbur <paologallina1992@gmail.com>
This commit is contained in:
paologallinaharbur
2020-05-22 13:46:17 +02:00
parent db19d46eb1
commit a4f815b5fd
2 changed files with 17 additions and 4 deletions

View File

@@ -45,7 +45,7 @@ func NewserviceCollector() (Collector, error) {
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"},
[]string{"name", "display_name", "process_id", "start_name"},
nil,
),
State: prometheus.NewDesc(
@@ -89,6 +89,7 @@ type Win32_Service struct {
State string
Status string
StartMode string
StartName *string
}
var (
@@ -131,9 +132,13 @@ func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
for _, service := range dst {
pid := strconv.FormatUint(uint64(service.ProcessId), 10)
startName := ""
if service.StartName != nil {
startName = *service.StartName
}
ch <- prometheus.MustNewConstMetric(
c.Information,
prometheus.GaugeValue,
@@ -141,6 +146,7 @@ func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
strings.ToLower(service.Name),
service.DisplayName,
pid,
startName,
)
for _, state := range allStates {