From: jweigele Date: Wed, 14 Aug 2024 02:43:28 +0000 (-0700) Subject: heap metrics on reprocess X-Git-Url: http://git.hexthepla.net/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=rabbit_go heap metrics on reprocess --- diff --git a/Dockerfile.reprocess b/Dockerfile.reprocess index 3d32555..0f68dac 100644 --- a/Dockerfile.reprocess +++ b/Dockerfile.reprocess @@ -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 diff --git a/reprocess/main.go b/reprocess/main.go index ad57131..6e7e569 100644 --- a/reprocess/main.go +++ b/reprocess/main.go @@ -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)