From 5122a5908003397c027e5db866ff2eebe8a2c00f Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sun, 9 Mar 2025 16:34:20 -0400 Subject: [PATCH] added dryrun debug on lxc storage --- hwmonDaemon.py | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/hwmonDaemon.py b/hwmonDaemon.py index 179446b..16ec181 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -1267,6 +1267,10 @@ class SystemHealthMonitor: try: # 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( ['pct', 'list'], stdout=subprocess.PIPE, @@ -1274,6 +1278,9 @@ class SystemHealthMonitor: text=True ) + if self.dry_run: + logger.debug(f"Raw pct list output:\n{result.stdout}") + # Skip header line and process each container for line in result.stdout.split('\n')[1:]: if not line.strip(): @@ -1281,7 +1288,14 @@ class SystemHealthMonitor: vmid, status, *_ = line.split() + if self.dry_run: + logger.debug(f"Processing container VMID: {vmid}, Status: {status}") + 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 disk_info = subprocess.run( ['pct', 'df', vmid], @@ -1290,6 +1304,9 @@ class SystemHealthMonitor: text=True ) + if self.dry_run: + logger.debug(f"Raw disk info for container {vmid}:\n{disk_info.stdout}") + container_info = { 'vmid': vmid, 'filesystems': [] @@ -1311,26 +1328,43 @@ class SystemHealthMonitor: '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 if usage_percent >= self.CONFIG['THRESHOLDS']['DISK_CRITICAL']: lxc_health['status'] = 'CRITICAL' - lxc_health['issues'].append( - f"LXC {vmid} critical storage usage: {usage_percent}% on {fs[5]}" - ) + issue = 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']: if lxc_health['status'] != 'CRITICAL': lxc_health['status'] = 'WARNING' - lxc_health['issues'].append( - f"LXC {vmid} high storage usage: {usage_percent}% on {fs[5]}" - ) + issue = 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) 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: 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