Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add battery charge metric #38

Merged
merged 1 commit into from
Jun 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ var (
Name: "inverter_power",
Help: "Power flow of the inverter in Watt",
}, []string{"inverter"})
inverterBatteryChargeGaugeVec = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Name: "inverter_soc",
Help: "State of charge of the battery attached to the inverter in percent",
}, []string{"inverter"})

sitePowerLoadGauge = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Expand Down Expand Up @@ -89,6 +94,7 @@ func parseMetrics(data *fronius.SymoData) {
log.WithField("data", *data).Debug("Parsing data.")
for key, inverter := range data.Inverters {
inverterPowerGaugeVec.WithLabelValues(key).Set(inverter.Power)
inverterBatteryChargeGaugeVec.WithLabelValues(key).Set(inverter.BatterySoC / 100)
}
sitePowerAccuGauge.Set(data.Site.PowerAccu)
sitePowerGridGauge.Set(data.Site.PowerGrid)
Expand Down
1 change: 1 addition & 0 deletions pkg/fronius/symo.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type (
Inverter struct {
DT float64 `json:"DT"`
Power float64 `json:"P"`
BatterySoC float64 `json:"SOC"`
EnergyDay float64 `json:"E_Day"`
EnergyYear float64 `json:"E_Year"`
EnergyTotal float64 `json:"E_Total"`
Expand Down
4 changes: 3 additions & 1 deletion pkg/fronius/symo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Test_Symo_GetPowerFlowData_GivenUrl_WhenRequestData_ThenParseStruct(t *test
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
payload, err := ioutil.ReadFile("testdata/example_1.json")
require.NoError(t, err)
rw.Write(payload)
_, _ = rw.Write(payload)
}))

c, err := NewSymoClient(ClientOptions{
Expand All @@ -33,4 +33,6 @@ func Test_Symo_GetPowerFlowData_GivenUrl_WhenRequestData_ThenParseStruct(t *test
assert.Equal(t, float64(22997), p.Site.EnergyDay)
assert.Equal(t, float64(43059100), p.Site.EnergyTotal)
assert.Equal(t, 3525577.75, p.Site.EnergyYear)

assert.Equal(t, 34.5, p.Inverters["1"].BatterySoC)
}
3 changes: 2 additions & 1 deletion pkg/fronius/testdata/example_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"E_Day" : 22997,
"E_Total" : 43059100,
"E_Year" : 3525577.75,
"P" : 0
"P" : 0,
"SOC": 34.5
}
},
"Site" : {
Expand Down