Produce metrics for nominal output power.

This commit is contained in:
Rolf Schäuble 2017-04-14 14:54:03 +02:00
parent 2400f7fb14
commit db1bca91ff
2 changed files with 17 additions and 0 deletions

View File

@ -31,6 +31,7 @@ type UPSCollector struct {
LastTransferOnBattery *prometheus.Desc
LastTransferOffBattery *prometheus.Desc
LastSelftest *prometheus.Desc
NominalPowerWatts *prometheus.Desc
ss StatusSource
}
@ -135,6 +136,13 @@ func NewUPSCollector(ss StatusSource) *UPSCollector {
nil,
),
NominalPowerWatts: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "apcupsd_nominal_power_watts"),
"Nominal power output in watts",
labels,
nil,
),
ss: ss,
}
}
@ -244,6 +252,13 @@ func (c *UPSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
labels...
)
ch <- prometheus.MustNewConstMetric(
c.NominalPowerWatts,
prometheus.GaugeValue,
float64(s.NominalPower),
labels...,
)
return nil, nil
}

View File

@ -45,6 +45,7 @@ func TestUPSCollector(t *testing.T) {
XOnBattery: time.Unix(100001, 0),
XOffBattery: time.Unix(100002, 0),
LastSelftest: time.Unix(100003, 0),
NominalPower: 50.0,
},
},
matches: []*regexp.Regexp{
@ -61,6 +62,7 @@ func TestUPSCollector(t *testing.T) {
regexp.MustCompile(`apcupsd_last_transfer_on_battery{hostname="a",model="b",ups_name="c"} 100001`),
regexp.MustCompile(`apcupsd_last_transfer_off_battery{hostname="a",model="b",ups_name="c"} 100002`),
regexp.MustCompile(`apcupsd_last_selftest{hostname="a",model="b",ups_name="c"} 100003`),
regexp.MustCompile(`apcupsd_nominal_power_watts{hostname="a",model="b",ups_name="c"} 50`),
},
},
}