From 8586852eef56cd7058031dba65afda4e42fdc706 Mon Sep 17 00:00:00 2001 From: jweigele Date: Sun, 14 Jan 2024 22:07:43 -0800 Subject: [PATCH] location was stomping on others in the gauges for ESP, so just hacked in the topic instead --- lights/main.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lights/main.go b/lights/main.go index 3b2ef07..a895e50 100644 --- a/lights/main.go +++ b/lights/main.go @@ -191,6 +191,10 @@ type IRGBFriendly interface { getFriendlyName() string } +type ITopicRelay interface { + getTopic() string +} + type IRelayData interface { getRelayData(red, green, blue float64) (map[string]interface{}, string) } @@ -589,6 +593,10 @@ func (relay *ESPRelay) getRoutingKey() string { return relay.Topic } +func (relay *ESPRelay) getTopic() string { + return relay.Topic +} + // RGBPico defs type PicoRelayData struct { parent *RGBPico @@ -787,12 +795,18 @@ func (manager *RGBManager) updateMetrics() { time.Sleep(time.Duration(1) * time.Second) for _, relay := range manager.relays { // did we get a friendly name capable relay? - curZig, ok := relay.(IRGBFriendly) + curZig, zigOk := relay.(IRGBFriendly) // this should give us a fairly unique value, location is friendlyname where enabled, otherwise location is location - if ok { + if zigOk { lightGauge.With(prometheus.Labels{"location": curZig.getFriendlyName()}).Set(curZig.getMetricValue()) } else { - lightGauge.With(prometheus.Labels{"location": relay.getLocation()}).Set(relay.getMetricValue()) + curTopic, topicOk := relay.(ITopicRelay) + if topicOk { + lightGauge.With(prometheus.Labels{"location": curTopic.getTopic()}).Set(relay.getMetricValue()) + } else { + + lightGauge.With(prometheus.Labels{"location": relay.getLocation()}).Set(relay.getMetricValue()) + } } } } -- 2.30.2