Skip to content

Commit

Permalink
Merge pull request #38 from ccremer/battery-soc
Browse files Browse the repository at this point in the history
Add battery charge metric
  • Loading branch information
ccremer authored Jun 26, 2021
2 parents ba5f97c + 4e3e4d9 commit 4884b98
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
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

0 comments on commit 4884b98

Please sign in to comment.