diff --git a/CHANGELOG.md b/CHANGELOG.md index 1661b44..02d2e3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ Previous changelog before 1.7 will not be noted here. +## [2.1.0] - 2023-12-18 + +- fix: set to NaN when sensor down + ## [2.0.0] - 2023-12-16 - refactor: restructure project to be much better diff --git a/server/services/sensor_manager.go b/server/services/sensor_manager.go index d4420fd..975f478 100644 --- a/server/services/sensor_manager.go +++ b/server/services/sensor_manager.go @@ -88,6 +88,7 @@ func (sensorManager *SensorManager) Register() { sensorManager.SetValue(math.NaN(), math.NaN()) } +// Set prometheus metric values, this also set HealthStatus to true func (sensorManager *SensorManager) SetValue(temperature float64, humidity float64) { if !math.IsNaN(temperature) && !math.IsNaN(humidity) { sensorManager.counters.pingReceived.Inc() @@ -110,12 +111,19 @@ func (sensorManager *SensorManager) SetValue(temperature float64, humidity float } } +// Check sensor idle, if it is not updated for too long, set value to NaN +// and HealthStatus to false, and send Discord Alert after a period of time func (sensorManager *SensorManager) HealthCheck() { idleTime := time.Since(sensorManager.lastUpdated).Seconds() if idleTime >= 15 { sensorManager.gauges.healthStatus.Set(0) sensorManager.values.healthStatus = false + + sensorManager.gauges.temperature.Set(math.NaN()) + sensorManager.values.temperature = math.NaN() + sensorManager.gauges.humidity.Set(math.NaN()) + sensorManager.values.humidity = math.NaN() } if MeetsThreshold(sensorManager.alertLevel, idleTime) {