Skip to content

Commit

Permalink
add new field / metric to the exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudsurf-digital committed Jan 2, 2024
1 parent a92f4c2 commit 1814765
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/collect/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func NewCollector(client shelly.Client, log *zap.Logger) *Collector {
"Current real AC power being drawn, in Watts",
[]string{"device", "meter"}, nil,
),
TotalWattMinutes: prometheus.NewDesc("shelly_meter_total_wattminutes",
"Total energy consumed by the attached electrical appliance in Watt-minute",
[]string{"device", "meter"}, nil,
),
RelayOn: prometheus.NewDesc("shelly_relay_on",
"Whether the channel is turned ON or OFF",
[]string{"device", "relay"}, nil,
Expand Down Expand Up @@ -107,6 +111,7 @@ type Collector struct {
TargetTemperature *prometheus.Desc
TargetEnabled *prometheus.Desc
BatteryStatus *prometheus.Desc
TotalWattMinutes *prometheus.Desc
}

func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
Expand Down Expand Up @@ -171,6 +176,8 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
meterID := strconv.Itoa(i)
ch <- prometheus.MustNewConstMetric(c.MeterPower, prometheus.GaugeValue, meter.Power,
status.MAC, meterID)
ch <- prometheus.MustNewConstMetric(c.TotalWattMinutes, prometheus.CounterValue, meter.Total,
status.MAC, meterID)
}

for i, relay := range status.Relays {
Expand Down
1 change: 1 addition & 0 deletions pkg/shelly/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Status struct {

type Meter struct {
Power float64
Total float64
}

type Relay struct {
Expand Down

0 comments on commit 1814765

Please sign in to comment.