Add additional tags and fields to apcupsd (#7065)

- new tags:
  - model
- new metrics:
  - battery_date
  - nominal_input_voltage
  - nominal_battery_voltage
  - nominal_power
  - firmware
This commit is contained in:
donvipre 2020-02-25 01:32:09 +01:00 committed by GitHub
parent eb29f46721
commit b127254cca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 20 deletions

View File

@ -25,6 +25,7 @@ apcupsd should be installed and it's daemon should be running.
- serial
- status (string representing the set status_flags)
- ups_name
- model
- fields:
- status_flags ([status-bits][])
- input_voltage
@ -36,6 +37,11 @@ apcupsd should be installed and it's daemon should be running.
- battery_voltage
- input_frequency
- time_on_battery_ns
- battery_date
- nominal_input_voltage
- nominal_battery_voltage
- nominal_power
- firmware

View File

@ -63,6 +63,7 @@ func (h *ApcUpsd) Gather(acc telegraf.Accumulator) error {
"serial": status.SerialNumber,
"ups_name": status.UPSName,
"status": status.Status,
"model": status.Model,
}
flags, err := strconv.ParseUint(strings.Fields(status.StatusFlags)[0], 0, 64)
@ -81,6 +82,11 @@ func (h *ApcUpsd) Gather(acc telegraf.Accumulator) error {
"battery_voltage": status.BatteryVoltage,
"input_frequency": status.LineFrequency,
"time_on_battery_ns": status.TimeOnBattery.Nanoseconds(),
"nominal_input_voltage": status.NominalInputVoltage,
"nominal_battery_voltage": status.NominalBatteryVoltage,
"nominal_power": status.NominalPower,
"firmware": status.Firmware,
"battery_date": status.BatteryDate,
}
acc.AddFields("apcupsd", fields, tags)

View File

@ -125,6 +125,7 @@ func TestApcupsdGather(t *testing.T) {
"serial": "ABC123",
"status": "ONLINE",
"ups_name": "BERTHA",
"model": "Model 12345",
},
fields: map[string]interface{}{
"status_flags": uint64(8),
@ -137,6 +138,11 @@ func TestApcupsdGather(t *testing.T) {
"output_voltage": float64(0),
"time_left_ns": int64(2790000000000),
"time_on_battery_ns": int64(0),
"nominal_input_voltage": float64(230),
"nominal_battery_voltage": float64(12),
"nominal_power": int(865),
"firmware": string("857.L3 .I USB FW:L3"),
"battery_date": time.Date(2016, time.September, 06, 0, 0, 0, 0, time.UTC),
},
out: genOutput,
},
@ -190,6 +196,7 @@ func genOutput() [][]byte {
"STATUS : ONLINE",
"STATFLAG : 0x08 Status Flag",
"UPSNAME : BERTHA",
"MODEL : Model 12345",
"DATE : 2016-09-06 22:13:28 -0400",
"HOSTNAME : example",
"LOADPCT : 13.0 Percent Load Capacity",
@ -198,7 +205,10 @@ func genOutput() [][]byte {
"TONBATT : 0 seconds",
"NUMXFERS : 0",
"SELFTEST : NO",
"NOMINV : 230 Volts",
"NOMBATTV : 12.0 Volts",
"NOMPOWER : 865 Watts",
"FIRMWARE : 857.L3 .I USB FW:L3",
}
var out [][]byte