mirror of
https://github.com/mdlayher/apcupsd_exporter.git
synced 2024-11-21 10:45:12 +01:00
apcupsd_exporter: add OutputVolts and InternalTemp (#15)
Co-authored-by: Malte Bögershausen <malteb@gmail.com>
This commit is contained in:
parent
6cf5b5de9a
commit
4f14ba2aa6
@ -24,6 +24,7 @@ type UPSCollector struct {
|
||||
BatteryChargePercent *prometheus.Desc
|
||||
LineVolts *prometheus.Desc
|
||||
LineNominalVolts *prometheus.Desc
|
||||
OutputVolts *prometheus.Desc
|
||||
BatteryVolts *prometheus.Desc
|
||||
BatteryNominalVolts *prometheus.Desc
|
||||
BatteryNumberTransfersTotal *prometheus.Desc
|
||||
@ -34,6 +35,7 @@ type UPSCollector struct {
|
||||
LastTransferOffBatteryTimeSeconds *prometheus.Desc
|
||||
LastSelftestTimeSeconds *prometheus.Desc
|
||||
NominalPowerWatts *prometheus.Desc
|
||||
InternalTemp *prometheus.Desc
|
||||
|
||||
ss StatusSource
|
||||
}
|
||||
@ -80,6 +82,13 @@ func NewUPSCollector(ss StatusSource) *UPSCollector {
|
||||
nil,
|
||||
),
|
||||
|
||||
OutputVolts: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "", "output_volts"),
|
||||
"Current AC output voltage.",
|
||||
labels,
|
||||
nil,
|
||||
),
|
||||
|
||||
BatteryVolts: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "", "battery_volts"),
|
||||
"Current UPS battery voltage.",
|
||||
@ -150,6 +159,13 @@ func NewUPSCollector(ss StatusSource) *UPSCollector {
|
||||
nil,
|
||||
),
|
||||
|
||||
InternalTemp: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "", "internal_temp"),
|
||||
"Internal temperature in °C.",
|
||||
labels,
|
||||
nil,
|
||||
),
|
||||
|
||||
ss: ss,
|
||||
}
|
||||
}
|
||||
@ -163,6 +179,7 @@ func (c *UPSCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
c.BatteryChargePercent,
|
||||
c.LineVolts,
|
||||
c.LineNominalVolts,
|
||||
c.OutputVolts,
|
||||
c.BatteryVolts,
|
||||
c.BatteryNominalVolts,
|
||||
c.BatteryNumberTransfersTotal,
|
||||
@ -173,6 +190,7 @@ func (c *UPSCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
c.LastTransferOffBatteryTimeSeconds,
|
||||
c.LastSelftestTimeSeconds,
|
||||
c.NominalPowerWatts,
|
||||
c.InternalTemp,
|
||||
}
|
||||
|
||||
for _, d := range ds {
|
||||
@ -225,6 +243,13 @@ func (c *UPSCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
s.UPSName,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.OutputVolts,
|
||||
prometheus.GaugeValue,
|
||||
s.OutputVoltage,
|
||||
s.UPSName,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.BatteryVolts,
|
||||
prometheus.GaugeValue,
|
||||
@ -294,6 +319,13 @@ func (c *UPSCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
float64(s.NominalPower),
|
||||
s.UPSName,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.InternalTemp,
|
||||
prometheus.GaugeValue,
|
||||
s.InternalTemp,
|
||||
s.UPSName,
|
||||
)
|
||||
}
|
||||
|
||||
func timestamp(t time.Time) float64 {
|
||||
|
@ -36,12 +36,14 @@ func TestUPSCollector(t *testing.T) {
|
||||
BatteryVoltage: 13.2,
|
||||
NominalInputVoltage: 120.0,
|
||||
LineVoltage: 121.1,
|
||||
OutputVoltage: 120.9,
|
||||
LoadPercent: 16.0,
|
||||
NumberTransfers: 1,
|
||||
XOnBattery: time.Unix(100001, 0),
|
||||
XOffBattery: time.Unix(100002, 0),
|
||||
LastSelftest: time.Unix(100003, 0),
|
||||
NominalPower: 50.0,
|
||||
InternalTemp: 26.4,
|
||||
},
|
||||
},
|
||||
matches: []*regexp.Regexp{
|
||||
@ -55,11 +57,13 @@ func TestUPSCollector(t *testing.T) {
|
||||
regexp.MustCompile(`apcupsd_info{hostname="foo",model="APC UPS",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`),
|
||||
regexp.MustCompile(`apcupsd_ups_load_percent{ups="bar"} 16`),
|
||||
regexp.MustCompile(`apcupsd_last_transfer_on_battery_time_seconds{ups="bar"} 100001`),
|
||||
regexp.MustCompile(`apcupsd_last_transfer_off_battery_time_seconds{ups="bar"} 100002`),
|
||||
regexp.MustCompile(`apcupsd_last_selftest_time_seconds{ups="bar"} 100003`),
|
||||
regexp.MustCompile(`apcupsd_nominal_power_watts{ups="bar"} 50`),
|
||||
regexp.MustCompile(`apcupsd_internal_temp{ups="bar"} 26.4`),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user