Add sensor reading status metrics

This commit is contained in:
Søren Rasmussen 2022-03-07 15:54:36 +01:00
parent b876de55f9
commit 19afd92dc8
4 changed files with 15 additions and 12 deletions

View file

@ -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

View file

@ -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)

View file

@ -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",
},
)

View file

@ -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()
}
}