From b127254cca22c4edaabd1b2b53a63732698de7e7 Mon Sep 17 00:00:00 2001 From: donvipre Date: Tue, 25 Feb 2020 01:32:09 +0100 Subject: [PATCH] Add additional tags and fields to apcupsd (#7065) - new tags: - model - new metrics: - battery_date - nominal_input_voltage - nominal_battery_voltage - nominal_power - firmware --- plugins/inputs/apcupsd/README.md | 6 ++++++ plugins/inputs/apcupsd/apcupsd.go | 26 +++++++++++++--------- plugins/inputs/apcupsd/apcupsd_test.go | 30 +++++++++++++++++--------- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/plugins/inputs/apcupsd/README.md b/plugins/inputs/apcupsd/README.md index be79ab4a8..97526d7ec 100644 --- a/plugins/inputs/apcupsd/README.md +++ b/plugins/inputs/apcupsd/README.md @@ -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 diff --git a/plugins/inputs/apcupsd/apcupsd.go b/plugins/inputs/apcupsd/apcupsd.go index 9a73c454a..a862bbfc8 100644 --- a/plugins/inputs/apcupsd/apcupsd.go +++ b/plugins/inputs/apcupsd/apcupsd.go @@ -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) @@ -71,16 +72,21 @@ func (h *ApcUpsd) Gather(acc telegraf.Accumulator) error { } fields := map[string]interface{}{ - "status_flags": flags, - "input_voltage": status.LineVoltage, - "load_percent": status.LoadPercent, - "battery_charge_percent": status.BatteryChargePercent, - "time_left_ns": status.TimeLeft.Nanoseconds(), - "output_voltage": status.OutputVoltage, - "internal_temp": status.InternalTemp, - "battery_voltage": status.BatteryVoltage, - "input_frequency": status.LineFrequency, - "time_on_battery_ns": status.TimeOnBattery.Nanoseconds(), + "status_flags": flags, + "input_voltage": status.LineVoltage, + "load_percent": status.LoadPercent, + "battery_charge_percent": status.BatteryChargePercent, + "time_left_ns": status.TimeLeft.Nanoseconds(), + "output_voltage": status.OutputVoltage, + "internal_temp": status.InternalTemp, + "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) diff --git a/plugins/inputs/apcupsd/apcupsd_test.go b/plugins/inputs/apcupsd/apcupsd_test.go index 2418faf85..dfad765b3 100644 --- a/plugins/inputs/apcupsd/apcupsd_test.go +++ b/plugins/inputs/apcupsd/apcupsd_test.go @@ -125,18 +125,24 @@ func TestApcupsdGather(t *testing.T) { "serial": "ABC123", "status": "ONLINE", "ups_name": "BERTHA", + "model": "Model 12345", }, fields: map[string]interface{}{ - "status_flags": uint64(8), - "battery_charge_percent": float64(0), - "battery_voltage": float64(0), - "input_frequency": float64(0), - "input_voltage": float64(0), - "internal_temp": float64(0), - "load_percent": float64(13), - "output_voltage": float64(0), - "time_left_ns": int64(2790000000000), - "time_on_battery_ns": int64(0), + "status_flags": uint64(8), + "battery_charge_percent": float64(0), + "battery_voltage": float64(0), + "input_frequency": float64(0), + "input_voltage": float64(0), + "internal_temp": float64(0), + "load_percent": float64(13), + "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