From: jweigele Date: Sat, 13 Apr 2024 03:33:42 +0000 (-0700) Subject: add humidity tracking under reprocess X-Git-Url: http://git.hexthepla.net/?a=commitdiff_plain;h=8eca8b77fba8b357119c176fea65c1dcc985be0d;p=rabbit_go add humidity tracking under reprocess --- diff --git a/reprocess/main.go b/reprocess/main.go index 2b42175..ad57131 100644 --- a/reprocess/main.go +++ b/reprocess/main.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "reflect" + "strconv" "strings" "sync" "time" @@ -67,6 +68,22 @@ var ( []string{"location"}, ) + co2Gauge = promauto.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "airsensor_co2", + Help: "CO2 PPM concentration", + }, + []string{"location"}, + ) + + humidityGauge = promauto.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "sensor_humidity", + Help: "Relative humidity 0-100%", + }, + []string{"location"}, + ) + versionGauge = promauto.NewGaugeVec( prometheus.GaugeOpts{ Name: "sensor_version", @@ -112,6 +129,8 @@ var ( pm10Expire = make(map[string]time.Time) pm25Expire = make(map[string]time.Time) aqiExpire = make(map[string]time.Time) + co2Expire = make(map[string]time.Time) + humidityExpire = make(map[string]time.Time) versionExpire = make(map[string]time.Time) uptimeExpire = make(map[string]time.Time) internalTempExpire = make(map[string]time.Time) @@ -290,6 +309,26 @@ func handleAQI(obj map[string]interface{}) { } +func handleCO2(location string, co2 float64) { + now := time.Now().UTC() + co2Gauge.With(prometheus.Labels{"location": location}).Set(co2) + + expireMutex.Lock() + defer expireMutex.Unlock() + + co2Expire[location] = now +} + +func handleRH(location string, humidity float64) { + now := time.Now().UTC() + humidityGauge.With(prometheus.Labels{"location": location}).Set(humidity) + + expireMutex.Lock() + defer expireMutex.Unlock() + + humidityExpire[location] = now +} + func handleVersion(obj map[string]interface{}) { now := time.Now().UTC() extAddr, ok := obj["ext"].(string) @@ -461,17 +500,17 @@ func hexCommon(location string, friendlyName string, obj map[string]interface{}, sendChannel <- sendThis } - pm25, ok := obj["pm25"].(float64) - if !ok { + pm25, pm25ok := obj["pm25"].(float64) + if !pm25ok { logger.V(3).Info("pm25 not found in data, ignoring", "obj", obj) } - pm10, ok := obj["pm10"].(float64) - if !ok { + pm10, pm10ok := obj["pm10"].(float64) + if !pm10ok { logger.V(3).Info("pm10 not found in data, ignoring", "obj", obj) } - if pm10 != 0.0 || pm25 != 0.0 { + if pm10ok && pm25ok { processPM25(location, pm10, pm25, sendChannel) } @@ -494,6 +533,19 @@ func hexCommon(location string, friendlyName string, obj map[string]interface{}, } } + co2, ok := obj["co2"].(float64) + if ok { + handleCO2(location, co2) + } + + rh, ok := obj["rh"].(string) + if ok { + rh_float, err := strconv.ParseFloat(rh, 64) + if err == nil { + handleRH(location, rh_float) + } + } + internal, ok := obj["internal"].(float64) if ok { if internal < -55.0 || internal > 125.0 { @@ -746,6 +798,8 @@ func expireStaleMetrics() { expireStaleMetric(pm10Expire, pm10Gauge) expireStaleMetric(pm25Expire, pm25Gauge) expireStaleMetric(aqiExpire, aqiGauge) + expireStaleMetric(co2Expire, co2Gauge) + expireStaleMetric(humidityExpire, humidityGauge) expireStaleMetric(versionExpire, versionGauge) expireStaleMetric(uptimeExpire, uptimeGauge) expireStaleMetric(internalTempExpire, internalTempGauge) diff --git a/wunder/main.go b/wunder/main.go index 42b44e0..b34cd68 100644 --- a/wunder/main.go +++ b/wunder/main.go @@ -216,8 +216,8 @@ func main() { os.Exit(1) } // off, somehow? - //const weatherStation string = "KWASEATT2696" - const weatherStation string = "KWASEATT2613" + const weatherStation string = "KWASEATT2696" + //const weatherStation string = "KWASEATT2613" const sleepTime time.Duration = 30 * time.Second //currentTemp, err := fetchTemp(weatherStation)