Skip to content

Commit

Permalink
Merge pull request #16 from joneskoo/main
Browse files Browse the repository at this point in the history
Add metrics for Shelly 3EM neutral
  • Loading branch information
cimnine authored Mar 4, 2024
2 parents d14981b + f14cba4 commit dbd078e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
36 changes: 36 additions & 0 deletions shelly/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ type Metrics struct {
PowerLimit *prometheus.GaugeVec
Current *prometheus.GaugeVec
CurrentLimit *prometheus.GaugeVec
NeutralCurrent *prometheus.GaugeVec
NeutralIxsum *prometheus.GaugeVec
NeutralMismatch *prometheus.GaugeVec
NeutralValid *prometheus.GaugeVec
Voltage *prometheus.GaugeVec
VoltageLimit *prometheus.GaugeVec
PowerFactor *prometheus.GaugeVec
Expand Down Expand Up @@ -69,6 +73,34 @@ func NewMetrics(reg *prometheus.Registry) *Metrics {
},
lineLabels,
),
NeutralCurrent: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "shelly_neutral_current_a",
Help: "The neutral current value in this instant.",
},
deviceLabels,
),
NeutralIxsum: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "shelly_neutral_ixsum_a",
Help: "The neutral ixsum value in this instant.",
},
deviceLabels,
),
NeutralMismatch: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "shelly_neutral_mismatch",
Help: "1 if the neutral is mismatched, else 0.",
},
deviceLabels,
),
NeutralValid: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "shelly_neutral_valid",
Help: "1 if the neutral is valid, else 0.",
},
deviceLabels,
),
Voltage: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "shelly_voltage_v",
Expand Down Expand Up @@ -251,6 +283,10 @@ func NewMetrics(reg *prometheus.Registry) *Metrics {
m.PowerLimit,
m.Current,
m.CurrentLimit,
m.NeutralCurrent,
m.NeutralIxsum,
m.NeutralMismatch,
m.NeutralValid,
m.Voltage,
m.VoltageLimit,
m.PowerFactor,
Expand Down
8 changes: 8 additions & 0 deletions shelly_v1/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,12 @@ func (s *ShellyV1) readEmeters(m *shelly.Metrics) {
m.TotalReturned.WithLabelValues(labels...).Add(emeter.TotalReturned)
m.Voltage.WithLabelValues(labels...).Add(emeter.Voltage)
}

if s.status.EmeterN != nil && s.status.EmeterN.IsValid {
labels := shelly.DeviceLabels(s.Shelly)
m.NeutralCurrent.WithLabelValues(labels...).Set(s.status.EmeterN.Current)
m.NeutralIxsum.WithLabelValues(labels...).Set(s.status.EmeterN.Ixsum)
m.NeutralValid.WithLabelValues(labels...).Set(shelly.BoolToFloat(s.status.EmeterN.IsValid))
m.NeutralMismatch.WithLabelValues(labels...).Set(shelly.BoolToFloat(s.status.EmeterN.Mismatch))
}
}

0 comments on commit dbd078e

Please sign in to comment.