added dryrun debug on lxc storage

This commit is contained in:
2025-03-09 16:34:20 -04:00
parent aefa9c2944
commit 5122a59080

View File

@ -1267,6 +1267,10 @@ class SystemHealthMonitor:
try: try:
# Get list of running LXC containers # Get list of running LXC containers
if self.dry_run:
logger.debug("=== LXC Storage Check (Dry Run) ===")
logger.debug("Executing: pct list")
result = subprocess.run( result = subprocess.run(
['pct', 'list'], ['pct', 'list'],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
@ -1274,6 +1278,9 @@ class SystemHealthMonitor:
text=True text=True
) )
if self.dry_run:
logger.debug(f"Raw pct list output:\n{result.stdout}")
# Skip header line and process each container # Skip header line and process each container
for line in result.stdout.split('\n')[1:]: for line in result.stdout.split('\n')[1:]:
if not line.strip(): if not line.strip():
@ -1281,7 +1288,14 @@ class SystemHealthMonitor:
vmid, status, *_ = line.split() vmid, status, *_ = line.split()
if self.dry_run:
logger.debug(f"Processing container VMID: {vmid}, Status: {status}")
if status.lower() == 'running': if status.lower() == 'running':
if self.dry_run:
logger.debug(f"Checking disk usage for container {vmid}")
logger.debug(f"Executing: pct df {vmid}")
# Get container disk usage # Get container disk usage
disk_info = subprocess.run( disk_info = subprocess.run(
['pct', 'df', vmid], ['pct', 'df', vmid],
@ -1290,6 +1304,9 @@ class SystemHealthMonitor:
text=True text=True
) )
if self.dry_run:
logger.debug(f"Raw disk info for container {vmid}:\n{disk_info.stdout}")
container_info = { container_info = {
'vmid': vmid, 'vmid': vmid,
'filesystems': [] 'filesystems': []
@ -1311,26 +1328,43 @@ class SystemHealthMonitor:
'usage_percent': usage_percent 'usage_percent': usage_percent
} }
if self.dry_run:
logger.debug(f"Container {vmid} filesystem details:")
logger.debug(f" Mountpoint: {filesystem['mountpoint']}")
logger.debug(f" Usage: {filesystem['used']}/{filesystem['total']} ({usage_percent}%)")
# Check thresholds # Check thresholds
if usage_percent >= self.CONFIG['THRESHOLDS']['DISK_CRITICAL']: if usage_percent >= self.CONFIG['THRESHOLDS']['DISK_CRITICAL']:
lxc_health['status'] = 'CRITICAL' lxc_health['status'] = 'CRITICAL'
lxc_health['issues'].append( issue = f"LXC {vmid} critical storage usage: {usage_percent}% on {fs[5]}"
f"LXC {vmid} critical storage usage: {usage_percent}% on {fs[5]}" lxc_health['issues'].append(issue)
) if self.dry_run:
logger.debug(f"Critical issue detected: {issue}")
elif usage_percent >= self.CONFIG['THRESHOLDS']['DISK_WARNING']: elif usage_percent >= self.CONFIG['THRESHOLDS']['DISK_WARNING']:
if lxc_health['status'] != 'CRITICAL': if lxc_health['status'] != 'CRITICAL':
lxc_health['status'] = 'WARNING' lxc_health['status'] = 'WARNING'
lxc_health['issues'].append( issue = f"LXC {vmid} high storage usage: {usage_percent}% on {fs[5]}"
f"LXC {vmid} high storage usage: {usage_percent}% on {fs[5]}" lxc_health['issues'].append(issue)
) if self.dry_run:
logger.debug(f"Warning issue detected: {issue}")
container_info['filesystems'].append(filesystem) container_info['filesystems'].append(filesystem)
lxc_health['containers'].append(container_info) lxc_health['containers'].append(container_info)
if self.dry_run:
logger.debug("=== LXC Storage Check Summary ===")
logger.debug(f"Status: {lxc_health['status']}")
logger.debug(f"Total containers checked: {len(lxc_health['containers'])}")
logger.debug(f"Issues found: {len(lxc_health['issues'])}")
logger.debug("=== End LXC Storage Check ===\n")
except Exception as e: except Exception as e:
lxc_health['status'] = 'ERROR' lxc_health['status'] = 'ERROR'
lxc_health['issues'].append(f"Error checking LXC storage: {str(e)}") error_msg = f"Error checking LXC storage: {str(e)}"
lxc_health['issues'].append(error_msg)
if self.dry_run:
logger.debug(f"Error during LXC storage check: {error_msg}")
return lxc_health return lxc_health