Increase history storage limit to 50MB to match retention needs

With 50 drives checked hourly over 30 days, history data can reach ~36MB
which exceeded the old 10MB limit causing constant file churn. Increase
to 50MB and make configurable via HISTORY_MAX_BYTES in .env.

Resolves #12

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-10 12:59:24 -05:00
parent da2de4375e
commit ab67d786ce

View File

@@ -127,7 +127,9 @@ class SystemHealthMonitor:
'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 # SMART analysis thresholds
'NEW_DRIVE_HOURS_THRESHOLD': 720, # Hours to consider a drive "new" (~30 days) '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) 'SMART_ERROR_RECENT_HOURS': 168, # Hours window for recent SMART errors (~1 week)
# Storage limits
'HISTORY_MAX_BYTES': 52428800 # 50MB max storage for history files
} }
@classmethod @classmethod
@@ -204,6 +206,11 @@ class SystemHealthMonitor:
cls.CONFIG['SMART_ERROR_RECENT_HOURS'] = int(value) cls.CONFIG['SMART_ERROR_RECENT_HOURS'] = int(value)
except ValueError: except ValueError:
logger.warning(f"Invalid SMART_ERROR_RECENT_HOURS value: {value}") logger.warning(f"Invalid SMART_ERROR_RECENT_HOURS value: {value}")
elif key == 'HISTORY_MAX_BYTES':
try:
cls.CONFIG['HISTORY_MAX_BYTES'] = int(value)
except ValueError:
logger.warning(f"Invalid HISTORY_MAX_BYTES value: {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}")
@@ -658,13 +665,15 @@ class SystemHealthMonitor:
# Ensure history directory exists # Ensure history directory exists
os.makedirs(self.CONFIG['HISTORY_DIR'], exist_ok=True) os.makedirs(self.CONFIG['HISTORY_DIR'], exist_ok=True)
def _enforce_storage_limit(self, history_dir: str, max_bytes: int = 10485760): def _enforce_storage_limit(self, history_dir: str, max_bytes: int = None):
""" """
Delete oldest history files if directory exceeds size limit (default 10MB). Delete oldest history files if directory exceeds size limit.
:param history_dir: Directory containing history files :param history_dir: Directory containing history files
:param max_bytes: Maximum directory size in bytes (default 10MB) :param max_bytes: Maximum directory size in bytes (default from CONFIG)
""" """
if max_bytes is None:
max_bytes = self.CONFIG.get('HISTORY_MAX_BYTES', 52428800)
if not os.path.exists(history_dir): if not os.path.exists(history_dir):
return return