Centralize hardcoded magic numbers into CONFIG dict
Move NEW_DRIVE_HOURS_THRESHOLD (720h) and SMART_ERROR_RECENT_HOURS (168h) from inline literals to configurable CONFIG entries with .env support. Resolves #20 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -124,7 +124,10 @@ class SystemHealthMonitor:
|
|||||||
# Prometheus metrics settings
|
# Prometheus metrics settings
|
||||||
'PROMETHEUS_ENABLED': False, # Enable Prometheus metrics export
|
'PROMETHEUS_ENABLED': False, # Enable Prometheus metrics export
|
||||||
'PROMETHEUS_PORT': 9101, # Port for Prometheus metrics HTTP server
|
'PROMETHEUS_PORT': 9101, # Port for Prometheus metrics HTTP server
|
||||||
'PROMETHEUS_TEXTFILE_PATH': None # Path for textfile collector (alternative to HTTP)
|
'PROMETHEUS_TEXTFILE_PATH': None, # Path for textfile collector (alternative to HTTP)
|
||||||
|
# SMART analysis thresholds
|
||||||
|
'NEW_DRIVE_HOURS_THRESHOLD': 720, # Hours to consider a drive "new" (~30 days)
|
||||||
|
'SMART_ERROR_RECENT_HOURS': 168 # Hours window for recent SMART errors (~1 week)
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -182,6 +185,10 @@ class SystemHealthMonitor:
|
|||||||
elif key == 'CLUSTER_NAME':
|
elif key == 'CLUSTER_NAME':
|
||||||
cls.CONFIG['CLUSTER_NAME'] = value if value else 'proxmox-cluster'
|
cls.CONFIG['CLUSTER_NAME'] = value if value else 'proxmox-cluster'
|
||||||
logger.info(f"✓ Loaded CLUSTER_NAME: {value}")
|
logger.info(f"✓ Loaded CLUSTER_NAME: {value}")
|
||||||
|
elif key == 'NEW_DRIVE_HOURS_THRESHOLD':
|
||||||
|
cls.CONFIG['NEW_DRIVE_HOURS_THRESHOLD'] = int(value)
|
||||||
|
elif key == 'SMART_ERROR_RECENT_HOURS':
|
||||||
|
cls.CONFIG['SMART_ERROR_RECENT_HOURS'] = int(value)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to load .env file: {e}")
|
logger.error(f"Failed to load .env file: {e}")
|
||||||
@@ -2266,7 +2273,7 @@ class SystemHealthMonitor:
|
|||||||
|
|
||||||
def _is_new_drive(self, power_on_hours: int) -> bool:
|
def _is_new_drive(self, power_on_hours: int) -> bool:
|
||||||
"""Determine if a drive is considered "new" based on power-on hours."""
|
"""Determine if a drive is considered "new" based on power-on hours."""
|
||||||
return power_on_hours < 720 # Less than 1 week of runtime
|
return power_on_hours < self.CONFIG['NEW_DRIVE_HOURS_THRESHOLD']
|
||||||
|
|
||||||
def _check_smart_health(self, device: str) -> Dict[str, Any]:
|
def _check_smart_health(self, device: str) -> Dict[str, Any]:
|
||||||
"""Enhanced SMART health check with better error handling and predictive analysis."""
|
"""Enhanced SMART health check with better error handling and predictive analysis."""
|
||||||
@@ -2501,7 +2508,7 @@ class SystemHealthMonitor:
|
|||||||
for match in error_matches:
|
for match in error_matches:
|
||||||
error_hour = int(match.group(1))
|
error_hour = int(match.group(1))
|
||||||
current_hours = smart_health['attributes'].get('Power_On_Hours', 0)
|
current_hours = smart_health['attributes'].get('Power_On_Hours', 0)
|
||||||
if current_hours - error_hour < 168: # Errors within last week
|
if current_hours - error_hour < self.CONFIG['SMART_ERROR_RECENT_HOURS']:
|
||||||
recent_errors.append(match.group(0))
|
recent_errors.append(match.group(0))
|
||||||
|
|
||||||
if recent_errors:
|
if recent_errors:
|
||||||
|
|||||||
Reference in New Issue
Block a user