apcupsd_exporter: add UPS status label to info metric

Signed-off-by: Matt Layher <mdlayher@gmail.com>
This commit is contained in:
Matt Layher 2022-03-14 12:09:25 -04:00
parent 420d526dee
commit 3f531e59fc
No known key found for this signature in database
GPG Key ID: 77BFE531397EDE94
2 changed files with 4 additions and 3 deletions

View File

@ -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(

View File

@ -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`),