Refactor configuration and health check server in POE project. Updated config.py to use environment variables for MQTT and health check settings, enhancing flexibility. Improved health check server in health_check.py with readiness endpoint and better error handling. Main application in main.py now includes graceful shutdown handling and health server verification. Adjusted Nomad job configuration for improved resource allocation and health check parameters.
This commit is contained in:
21
config.py
21
config.py
@ -1,4 +1,5 @@
|
||||
import time
|
||||
import os
|
||||
|
||||
# Modbus configuration
|
||||
MODBUS_HOSTS = [
|
||||
@ -14,22 +15,22 @@ MODBUS_PORT = 505
|
||||
UNIT_ID = 1
|
||||
|
||||
# MQTT configuration
|
||||
MQTT_BROKER = "mqtt.service.mesh"
|
||||
MQTT_PORT = 1883
|
||||
MQTT_BROKER = os.getenv("MQTT_BROKER", "mqtt.service.mesh")
|
||||
MQTT_PORT = int(os.getenv("MQTT_PORT", 1883))
|
||||
# Legacy topic - now using dynamic topic structure: {location}/{sensor_type}/data
|
||||
MQTT_TOPIC = "Temperature_Humidity" # Keep for backward compatibility
|
||||
MQTT_CLIENT_ID = f"modbus-mqtt-client-{int(time.time())}"
|
||||
MQTT_USERNAME = "relay"
|
||||
MQTT_PASSWORD = "Sey@K9c&Q4^"
|
||||
MQTT_USERNAME = os.getenv("MQTT_USERNAME", "relay")
|
||||
MQTT_PASSWORD = os.getenv("MQTT_PASSWORD", "Sey@K9c&Q4^")
|
||||
|
||||
# Read and publish cycle configuration (seconds)
|
||||
PUBLISH_INTERVAL = 10
|
||||
PUBLISH_INTERVAL = int(os.getenv("PUBLISH_INTERVAL", 10))
|
||||
|
||||
# Health check and alerting configuration
|
||||
HEALTH_CHECK_PORT = 8080
|
||||
HEALTH_CHECK_ENABLED = True
|
||||
HEALTH_CHECK_PORT = int(os.getenv("HEALTH_CHECK_PORT", 8080))
|
||||
HEALTH_CHECK_ENABLED = os.getenv("HEALTH_CHECK_ENABLED", "true").lower() in ["true", "1", "yes"]
|
||||
|
||||
# Alerting configuration
|
||||
ALERTING_ENABLED = True
|
||||
SENSOR_TIMEOUT_THRESHOLD = 3 # Number of consecutive failures before alert
|
||||
RECOVERY_CONFIRMATION_COUNT = 2 # Number of consecutive successes to confirm recovery
|
||||
ALERTING_ENABLED = os.getenv("ALERTING_ENABLED", "true").lower() in ["true", "1", "yes"]
|
||||
SENSOR_TIMEOUT_THRESHOLD = int(os.getenv("SENSOR_TIMEOUT_THRESHOLD", 3)) # Number of consecutive failures before alert
|
||||
RECOVERY_CONFIRMATION_COUNT = int(os.getenv("RECOVERY_CONFIRMATION_COUNT", 2)) # Number of consecutive successes to confirm recovery
|
||||
|
Reference in New Issue
Block a user