From 19afd92dc8517e10d691142ed913a4837976f3c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Rasmussen?= Date: Mon, 7 Mar 2022 15:54:36 +0100 Subject: [PATCH] Add sensor reading status metrics --- README.md | 6 ++++++ cmd/fermentord/config.go | 2 +- internal/metrics/prometheus.go | 10 +++++----- pkg/temperature/ds18b20.go | 9 +++------ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5e0dda7..fdfe1fe 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,12 @@ Control the temperature of your fermentation process. +# TODO + +* Cooler should not have min runtime, but run till min. temp cool level + * E.g. cool until setpoint - 1 degrees is reached + * ...or just make the damned PID work + # Epics ## Heater/Cooler diff --git a/cmd/fermentord/config.go b/cmd/fermentord/config.go index 02d18f2..d0a8fc7 100644 --- a/cmd/fermentord/config.go +++ b/cmd/fermentord/config.go @@ -57,7 +57,7 @@ func loadConfiguration() *controllers.ControllerConfig { } func reloadConfiguration(config *controllers.ControllerConfig, ctrl *controllers.ChamberController) { - + log.Printf("Reloading configuration") log.Printf("Ambient sensor: %v", config.Sensor.Ambient) log.Printf("Chamber sensor: %v", config.Sensor.Chamber) log.Printf("Wort sensor : %v", config.Sensor.Wort) diff --git a/internal/metrics/prometheus.go b/internal/metrics/prometheus.go index bc0683c..0be6df8 100644 --- a/internal/metrics/prometheus.go +++ b/internal/metrics/prometheus.go @@ -31,16 +31,16 @@ var ( }, ) - TemperatureSensorReadingDurationSeconds = promauto.NewHistogramVec( - prometheus.HistogramOpts{ + TemperatureSensorReadingStatus = promauto.NewCounterVec( + prometheus.CounterOpts{ Namespace: "fermentord", Subsystem: "temperature", - Name: "sensor_reading_duration_seconds", - Help: "Duration of temperature sensor readings.", - Buckets: []float64{0.25, 0.5, 0.75, 1, 1.25, 1.5}, + Name: "sensor_reading_status", + Help: "Temperature sensor reading status", }, []string{ "sensor", + "status", }, ) diff --git a/pkg/temperature/ds18b20.go b/pkg/temperature/ds18b20.go index e44084a..b0269ca 100644 --- a/pkg/temperature/ds18b20.go +++ b/pkg/temperature/ds18b20.go @@ -104,14 +104,13 @@ func PollSensors(ctx context.Context, wg *sync.WaitGroup, readingInterval time.D func readSensors(hub *sentry.Hub) { for _, sensor := range sensors { - start := time.Now() t, err := read(sensor) - dur := time.Since(start).Seconds() if err != nil { accErrSensor[sensor]++ hub.CaptureException(err) log.Printf("Error reading temperature sensor %v: %v", sensor, err) + metrics.TemperatureSensorReadingStatus.WithLabelValues(sensor, "failed").Inc() continue } @@ -127,11 +126,9 @@ func readSensors(hub *sentry.Hub) { WithLabelValues(sensor). Set(r.Degrees()) - metrics.TemperatureSensorReadingDurationSeconds. - WithLabelValues(sensor). - Observe(dur) - C <- r + + metrics.TemperatureSensorReadingStatus.WithLabelValues(sensor, "ok").Inc() } }