Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
upsd: use "ups.realpower" if available for "ups_load_usage" chart (#1444
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ilyam8 authored Dec 15, 2023
1 parent 8a950a8 commit 64c676d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions modules/upsd/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ func writeVar(mx map[string]int64, ups upsUnit, v string) {
}

func writeUpsLoadUsage(mx map[string]int64, ups upsUnit) {
if hasVar(ups.vars, varUpsRealPower) {
pow, _ := strconv.ParseFloat(ups.vars[varUpsRealPower], 64)
mx[prefix(ups)+"ups.load.usage"] = int64(pow * varPrecision)
return
}

if !hasVar(ups.vars, varUpsLoad) || !hasVar(ups.vars, varUpsRealPowerNominal) {
return
}
Expand Down
3 changes: 2 additions & 1 deletion modules/upsd/upsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestUpsd_Collect(t *testing.T) {
"ups_cp1500_input.voltage.nominal": 23000,
"ups_cp1500_output.voltage": 26000,
"ups_cp1500_ups.load": 800,
"ups_cp1500_ups.load.usage": 7200,
"ups_cp1500_ups.load.usage": 4300,
"ups_cp1500_ups.realpower.nominal": 90000,
"ups_cp1500_ups.status.BOOST": 0,
"ups_cp1500_ups.status.BYPASS": 0,
Expand Down Expand Up @@ -409,6 +409,7 @@ func (m *mockUpsdConn) upsUnits() ([]upsUnit, error) {
"ups.mfr": "CPS",
"ups.model": "CP1500EPFCLCD",
"ups.productid": "0501",
"ups.realpower": "43",
"ups.realpower.nominal": "900",
"ups.serial": "CRMNO2000312",
"ups.status": "OL",
Expand Down
1 change: 1 addition & 0 deletions modules/upsd/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
varOutputFrequencyNominal = "output.frequency.nominal"

varUpsLoad = "ups.load"
varUpsRealPower = "ups.realpower"
varUpsRealPowerNominal = "ups.realpower.nominal"
varUpsTemperature = "ups.temperature"
varUpsStatus = "ups.status"
Expand Down

0 comments on commit 64c676d

Please sign in to comment.