From 3f531e59fc85ebd86ce9806a1336818c5db18bcb Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Mon, 14 Mar 2022 12:09:25 -0400 Subject: [PATCH] apcupsd_exporter: add UPS status label to info metric Signed-off-by: Matt Layher --- upscollector.go | 4 ++-- upscollector_test.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/upscollector.go b/upscollector.go index d0b536e..e838c28 100644 --- a/upscollector.go +++ b/upscollector.go @@ -50,7 +50,7 @@ func NewUPSCollector(ss StatusSource) *UPSCollector { Info: prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "info"), "Metadata about a given UPS.", - []string{"ups", "hostname", "model"}, + []string{"ups", "hostname", "model", "status"}, nil, ), @@ -212,7 +212,7 @@ func (c *UPSCollector) Collect(ch chan<- prometheus.Metric) { c.Info, prometheus.GaugeValue, 1, - s.UPSName, s.Hostname, s.Model, + s.UPSName, s.Hostname, s.Model, s.Status, ) ch <- prometheus.MustNewConstMetric( diff --git a/upscollector_test.go b/upscollector_test.go index bafb11d..e760023 100644 --- a/upscollector_test.go +++ b/upscollector_test.go @@ -27,6 +27,7 @@ func TestUPSCollector(t *testing.T) { Hostname: "foo", Model: "APC UPS", UPSName: "bar", + Status: "ONLINE", BatteryChargePercent: 100.0, CumulativeTimeOnBattery: 30 * time.Second, @@ -54,7 +55,7 @@ func TestUPSCollector(t *testing.T) { regexp.MustCompile(`apcupsd_battery_time_on_seconds{ups="bar"} 10`), regexp.MustCompile(`apcupsd_battery_volts{ups="bar"} 13.2`), regexp.MustCompile(`apcupsd_battery_number_transfers_total{ups="bar"} 1`), - regexp.MustCompile(`apcupsd_info{hostname="foo",model="APC UPS",ups="bar"} 1`), + regexp.MustCompile(`apcupsd_info{hostname="foo",model="APC UPS",status="ONLINE",ups="bar"} 1`), regexp.MustCompile(`apcupsd_line_nominal_volts{ups="bar"} 120`), regexp.MustCompile(`apcupsd_line_volts{ups="bar"} 121.1`), regexp.MustCompile(`apcupsd_output_volts{ups="bar"} 120.9`),