From 5ae21dc464157ab3486acf686d36210556de0468 Mon Sep 17 00:00:00 2001 From: Markus Blaschke Date: Sun, 8 Oct 2023 00:02:31 +0200 Subject: [PATCH] fix shellypro 3em metrics Signed-off-by: Markus Blaschke --- shellyplug/metrics.go | 10 ++++++++++ shellyplug/prober.gen2.go | 24 +++++++++--------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/shellyplug/metrics.go b/shellyplug/metrics.go index c1a5578..9759768 100644 --- a/shellyplug/metrics.go +++ b/shellyplug/metrics.go @@ -27,6 +27,7 @@ type ( powerFactor *prometheus.GaugeVec powerFrequency *prometheus.GaugeVec powerVoltage *prometheus.GaugeVec + powerAmpere *prometheus.GaugeVec sysUnixtime *prometheus.GaugeVec sysUptime *prometheus.GaugeVec @@ -234,6 +235,15 @@ func (sp *ShellyPlug) initMetrics() { ) sp.registry.MustRegister(sp.prometheus.powerVoltage) + sp.prometheus.powerAmpere = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "shellyplug_power_ampere", + Help: "ShellyPlug configured power ampere", + }, + powerLabels, + ) + sp.registry.MustRegister(sp.prometheus.powerAmpere) + // ########################################## // System diff --git a/shellyplug/prober.gen2.go b/shellyplug/prober.gen2.go index a9bc7ca..1f3599d 100644 --- a/shellyplug/prober.gen2.go +++ b/shellyplug/prober.gen2.go @@ -70,8 +70,9 @@ func (sp *ShellyPlug) collectFromTargetGen2(target discovery.DiscoveryTarget, lo powerUsageLabels := copyLabelMap(targetLabels) powerUsageLabels["id"] = fmt.Sprintf("switch:%d", configData.Id) powerUsageLabels["name"] = configData.Name - sp.prometheus.powerCurrent.With(powerUsageLabels).Set(result.Current) - sp.prometheus.powerTotal.With(powerUsageLabels).Set(result.Apower) + sp.prometheus.powerCurrent.With(powerUsageLabels).Set(result.Apower) + sp.prometheus.powerVoltage.With(powerUsageLabels).Set(result.Voltage) + sp.prometheus.powerAmpere.With(powerUsageLabels).Set(result.Current) } else { logger.Errorf(`failed to decode switchStatus: %v`, err) } @@ -84,41 +85,34 @@ func (sp *ShellyPlug) collectFromTargetGen2(target discovery.DiscoveryTarget, lo powerUsageLabels := copyLabelMap(targetLabels) powerUsageLabels["id"] = fmt.Sprintf("em:%d:A", configData.Id) powerUsageLabels["name"] = configData.Name - sp.prometheus.powerCurrent.With(powerUsageLabels).Set(result.ACurrent) + sp.prometheus.powerCurrent.With(powerUsageLabels).Set(result.AActPower) sp.prometheus.powerApparentCurrent.With(powerUsageLabels).Set(result.AAprtPower) - sp.prometheus.powerTotal.With(powerUsageLabels).Set(result.AActPower) sp.prometheus.powerFactor.With(powerUsageLabels).Set(result.APf) sp.prometheus.powerFrequency.With(powerUsageLabels).Set(result.AFreq) sp.prometheus.powerVoltage.With(powerUsageLabels).Set(result.AVoltage) + sp.prometheus.powerAmpere.With(powerUsageLabels).Set(result.ACurrent) // phase B powerUsageLabels = copyLabelMap(targetLabels) powerUsageLabels["id"] = fmt.Sprintf("em:%d:B", configData.Id) powerUsageLabels["name"] = configData.Name - sp.prometheus.powerCurrent.With(powerUsageLabels).Set(result.BCurrent) + sp.prometheus.powerCurrent.With(powerUsageLabels).Set(result.BActPower) sp.prometheus.powerApparentCurrent.With(powerUsageLabels).Set(result.BAprtPower) - sp.prometheus.powerTotal.With(powerUsageLabels).Set(result.BActPower) sp.prometheus.powerFactor.With(powerUsageLabels).Set(result.BPf) sp.prometheus.powerFrequency.With(powerUsageLabels).Set(result.BFreq) sp.prometheus.powerVoltage.With(powerUsageLabels).Set(result.BVoltage) + sp.prometheus.powerAmpere.With(powerUsageLabels).Set(result.BCurrent) // phase C powerUsageLabels = copyLabelMap(targetLabels) powerUsageLabels["id"] = fmt.Sprintf("em:%d:C", configData.Id) powerUsageLabels["name"] = configData.Name - sp.prometheus.powerCurrent.With(powerUsageLabels).Set(result.CCurrent) + sp.prometheus.powerCurrent.With(powerUsageLabels).Set(result.CActPower) sp.prometheus.powerApparentCurrent.With(powerUsageLabels).Set(result.CAprtPower) - sp.prometheus.powerTotal.With(powerUsageLabels).Set(result.CActPower) sp.prometheus.powerFactor.With(powerUsageLabels).Set(result.CPf) sp.prometheus.powerFrequency.With(powerUsageLabels).Set(result.CFreq) sp.prometheus.powerVoltage.With(powerUsageLabels).Set(result.CVoltage) - - // phase C - powerUsageLabels = copyLabelMap(targetLabels) - powerUsageLabels["id"] = "em:total" - powerUsageLabels["name"] = configData.Name - sp.prometheus.powerCurrent.With(powerUsageLabels).Set(result.TotalCurrent) - sp.prometheus.powerTotal.With(powerUsageLabels).Set(result.TotalActPower) + sp.prometheus.powerAmpere.With(powerUsageLabels).Set(result.CCurrent) } else { logger.Errorf(`failed to decode switchStatus: %v`, err) }