Skip to content

Commit

Permalink
Add additional tags and fields to apcupsd (influxdata#7065)
Browse files Browse the repository at this point in the history
- new tags:
  - model
- new metrics:
  - battery_date
  - nominal_input_voltage
  - nominal_battery_voltage
  - nominal_power
  - firmware
  • Loading branch information
donvipre authored Feb 25, 2020
1 parent 8ea42e2 commit e478339
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
6 changes: 6 additions & 0 deletions plugins/inputs/apcupsd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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



Expand Down
26 changes: 16 additions & 10 deletions plugins/inputs/apcupsd/apcupsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
30 changes: 20 additions & 10 deletions plugins/inputs/apcupsd/apcupsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand Down

0 comments on commit e478339

Please sign in to comment.