Cache drive details to eliminate redundant smartctl calls
Add per-run cache for _get_drive_details() results. Each drive is queried once via smartctl -i and the result is reused across SMART health checks and ticket creation. Resolves #15 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -665,6 +665,9 @@ class SystemHealthMonitor:
|
||||
# Ensure history directory exists
|
||||
os.makedirs(self.CONFIG['HISTORY_DIR'], exist_ok=True)
|
||||
|
||||
# Drive details cache (per-run, cleared on next execution)
|
||||
self._drive_details_cache = {}
|
||||
|
||||
def _enforce_storage_limit(self, history_dir: str, max_bytes: int = None):
|
||||
"""
|
||||
Delete oldest history files if directory exceeds size limit.
|
||||
@@ -1072,7 +1075,10 @@ class SystemHealthMonitor:
|
||||
# DRIVE HEALTH CHECKING METHODS
|
||||
# =============================================================================
|
||||
def _get_drive_details(self, device: str) -> Dict[str, str]:
|
||||
"""Get detailed drive information using smartctl."""
|
||||
"""Get detailed drive information using smartctl (cached per run)."""
|
||||
if device in self._drive_details_cache:
|
||||
return self._drive_details_cache[device]
|
||||
|
||||
drive_details = {
|
||||
'model': None,
|
||||
'serial': None,
|
||||
@@ -1127,6 +1133,7 @@ class SystemHealthMonitor:
|
||||
except Exception as e:
|
||||
logger.debug(f"Error getting drive details for {device}: {e}")
|
||||
|
||||
self._drive_details_cache[device] = drive_details
|
||||
return drive_details
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user