From: jweigele Date: Tue, 20 Feb 2024 01:08:59 +0000 (-0800) Subject: Add version parsing to esp32 devices X-Git-Url: http://git.hexthepla.net/?a=commitdiff_plain;h=6b489a393d9421c4c7b96a42bb39d99a58b0a153;p=rabbit_go Add version parsing to esp32 devices This simply uses a global topic bind and then sets gauges internally, with approrpriate labels for each value. Expiration is similarly kinda complicated. --- diff --git a/mattersocket/mattersocket.go b/mattersocket/mattersocket.go index 63dc817..5280c8a 100644 --- a/mattersocket/mattersocket.go +++ b/mattersocket/mattersocket.go @@ -42,7 +42,7 @@ type MatterSocket struct { } func (matter *MatterSocket) Init() { - matter.Address = "iotbridge:5580" + matter.Address = "matterbridge:5580" flag.Parse() log.SetFlags(0) diff --git a/reprocess/main.go b/reprocess/main.go index fc6d0c0..2b42175 100644 --- a/reprocess/main.go +++ b/reprocess/main.go @@ -67,6 +67,14 @@ var ( []string{"location"}, ) + versionGauge = promauto.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "sensor_version", + Help: "Various information to map a hardware sensor back to compiled version", + }, + []string{"location", "app_version", "idf_version", "mac", "ext"}, + ) + uptimeGauge = promauto.NewGaugeVec( prometheus.GaugeOpts{ Name: "sensor_uptime", @@ -104,6 +112,7 @@ var ( pm10Expire = make(map[string]time.Time) pm25Expire = make(map[string]time.Time) aqiExpire = make(map[string]time.Time) + versionExpire = make(map[string]time.Time) uptimeExpire = make(map[string]time.Time) internalTempExpire = make(map[string]time.Time) @@ -281,6 +290,26 @@ func handleAQI(obj map[string]interface{}) { } +func handleVersion(obj map[string]interface{}) { + now := time.Now().UTC() + extAddr, ok := obj["ext"].(string) + if !ok { + extAddr = "" + } + versionGauge.With(prometheus.Labels{"location": obj["location"].(string), + "app_version": obj["app_version"].(string), + "idf_version": obj["idf_version"].(string), + "mac": obj["mac"].(string), + "ext": extAddr, + }).Set(1) + + versionHash := labelValHash{labelValues: []string{obj["location"].(string), obj["app_version"].(string), obj["idf_version"].(string), obj["mac"].(string), extAddr}} + expireMutex.Lock() + defer expireMutex.Unlock() + versionExpire[versionHash.getHash()] = now + +} + func processPM25(location string, pm10 float64, pm25 float64, sendChannel chan helper.RabbitSend) { // should have the senseType setup correctly now, if we're still here dataMap := make(map[string]interface{}, 0) @@ -568,6 +597,13 @@ func readLoop(channel chan helper.RabbitSend, devices []device, rabbit helper.Ra os.Exit(1) } + /// this one is hardcoded, for the generic sensor version info + err = helper.Bind("esp32.version_info", &rabbit) + if err != nil { + logger.Error(err, "unable to bind successfully to exchange", "routingKey", "esp32.version_info") + os.Exit(1) + } + deliveries, err := helper.StartConsuming(rabbit) if err != nil { logger.Error(err, "unable to start consuming data from rabbit") @@ -593,6 +629,8 @@ func readLoop(channel chan helper.RabbitSend, devices []device, rabbit helper.Ra handleTemp(item) } else if delivery.RoutingKey == "aqi" { handleAQI(item) + } else if delivery.RoutingKey == "esp32.version_info" { + handleVersion(item) } for _, device := range devices { if device.getRoutingKey() == delivery.RoutingKey { @@ -708,6 +746,7 @@ func expireStaleMetrics() { expireStaleMetric(pm10Expire, pm10Gauge) expireStaleMetric(pm25Expire, pm25Gauge) expireStaleMetric(aqiExpire, aqiGauge) + expireStaleMetric(versionExpire, versionGauge) expireStaleMetric(uptimeExpire, uptimeGauge) expireStaleMetric(internalTempExpire, internalTempGauge)