heap metrics on reprocess master
authorjweigele <jweigele@local>
Wed, 14 Aug 2024 02:43:28 +0000 (19:43 -0700)
committerjweigele <jweigele@local>
Wed, 14 Aug 2024 02:43:28 +0000 (19:43 -0700)
Dockerfile.reprocess
reprocess/main.go

index 3d325552716ce8dffd6e38db26b099b2e03c8bce..0f68dacd69d06a6eaee7df2bb5fa8b068f09a0a9 100644 (file)
@@ -1,5 +1,5 @@
 # STEP 1 build executable binary
-FROM golang:alpine as builder
+FROM golang:alpine AS builder
 # Install SSL ca certificates
 RUN apk update && apk add git && apk add ca-certificates
 # Create appuser
index ad571314c919f20feec9deca03fffab7e484db7e..6e7e569eeebecb9ed4792d2b34eb42a510c9b1bc 100644 (file)
@@ -92,6 +92,14 @@ var (
                []string{"location", "app_version", "idf_version", "mac", "ext"},
        )
 
+       heapGauge = promauto.NewGaugeVec(
+               prometheus.GaugeOpts{
+                       Name: "sensor_heap",
+                       Help: "Heap free for a given mac",
+               },
+               []string{"location"},
+       )
+
        uptimeGauge = promauto.NewGaugeVec(
                prometheus.GaugeOpts{
                        Name: "sensor_uptime",
@@ -132,6 +140,7 @@ var (
        co2Expire          = make(map[string]time.Time)
        humidityExpire     = make(map[string]time.Time)
        versionExpire      = make(map[string]time.Time)
+       heapExpire         = make(map[string]time.Time)
        uptimeExpire       = make(map[string]time.Time)
        internalTempExpire = make(map[string]time.Time)
 
@@ -342,9 +351,10 @@ func handleVersion(obj map[string]interface{}) {
                "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()
+
+       versionHash := labelValHash{labelValues: []string{obj["location"].(string), obj["app_version"].(string), obj["idf_version"].(string), obj["mac"].(string), extAddr}}
        versionExpire[versionHash.getHash()] = now
 
 }
@@ -562,6 +572,18 @@ func hexCommon(location string, friendlyName string, obj map[string]interface{},
                processUptime(location, friendlyName, uptime, sendChannel)
        }
 
+       // older versions don't contain heap
+       heapVal, ok := obj["heap"].(float64)
+       if ok {
+               now := time.Now().UTC()
+               expireMutex.Lock()
+               defer expireMutex.Unlock()
+               heapGauge.With(prometheus.Labels{"location": obj["location"].(string)}).Set(heapVal)
+               heapHash := labelValHash{labelValues: []string{obj["location"].(string)}}
+               heapExpire[heapHash.getHash()] = now
+
+       }
+
 }
 func (dev *hexdevice) handleHex(obj map[string]interface{}, sendChannel chan helper.RabbitSend) {
        //now := time.Now().UTC()
@@ -801,6 +823,7 @@ func expireStaleMetrics() {
        expireStaleMetric(co2Expire, co2Gauge)
        expireStaleMetric(humidityExpire, humidityGauge)
        expireStaleMetric(versionExpire, versionGauge)
+       expireStaleMetric(heapExpire, heapGauge)
        expireStaleMetric(uptimeExpire, uptimeGauge)
        expireStaleMetric(internalTempExpire, internalTempGauge)