diff --git a/hwmonDaemon.py b/hwmonDaemon.py index 230a857..69e0a0b 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -1330,7 +1330,7 @@ class SystemHealthMonitor: if self.dry_run: logger.debug("=== LXC Storage Check (Dry Run) ===") logger.debug("Executing: pct list") - + result = subprocess.run( ['pct', 'list'], stdout=subprocess.PIPE, @@ -1338,9 +1338,6 @@ class SystemHealthMonitor: text=True ) - if self.dry_run: - logger.debug(f"Raw pct list output:\n{result.stdout}") - for line in result.stdout.split('\n')[1:]: if not line.strip(): continue @@ -1351,14 +1348,7 @@ class SystemHealthMonitor: vmid, status = parts[0], parts[1] - 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}") - disk_info = subprocess.run( ['pct', 'df', vmid], stdout=subprocess.PIPE, @@ -1366,9 +1356,6 @@ 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': [] @@ -1380,48 +1367,35 @@ class SystemHealthMonitor: try: parts = fs_line.split() - if len(parts) >= 6: mountpoint = parts[5] # Get the Path column - logger.debug(f"parts 1: {parts[1]}") - logger.debug(f"parts 2: {parts[2]}") - logger.debug(f"parts 3: {parts[3]}") - logger.debug(f"parts 4: {parts[4]}") - logger.debug(f"parts 5: {parts[5]}") - logger.debug(f"parts 6: {parts[6]}") - usage_percent = float(parts[4].rstrip('%')) # Get the Use% column - # Check exclusion patterns - if any(re.match(pattern, mountpoint) for pattern in self.CONFIG['EXCLUDED_PATTERNS']): - logger.debug(f"Excluded mountpoint: {mountpoint}") + # Skip excluded mountpoints + if any(pattern in mountpoint for pattern in ['/media', '/mnt/pve/mediafs', '/opt/metube_downloads']): + if self.dry_run: + logger.debug(f"Skipping excluded mountpoint: {mountpoint}") continue - + + # Get usage percentage directly from parts[4] + usage_percent = float(parts[4].rstrip('%')) + filesystem = { 'mountpoint': mountpoint, - 'total': parts[2], - 'used': parts[3], - 'available': parts[4], + 'total': parts[1], + 'used': parts[2], + 'available': parts[3], '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: {used}/{total} ({usage_percent}%)") - if usage_percent >= self.CONFIG['THRESHOLDS']['DISK_CRITICAL']: lxc_health['status'] = 'CRITICAL' - issue = f"LXC {vmid} critical storage usage: {usage_percent}% on {parts[5]}" + issue = f"LXC {vmid} critical storage usage: {usage_percent}% on {mountpoint}" 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' - issue = f"LXC {vmid} high storage usage: {usage_percent}% on {parts[5]}" + issue = f"LXC {vmid} high storage usage: {usage_percent}% on {mountpoint}" lxc_health['issues'].append(issue) - if self.dry_run: - logger.debug(f"Warning issue detected: {issue}") container_info['filesystems'].append(filesystem) except Exception as e: @@ -1447,6 +1421,7 @@ class SystemHealthMonitor: return lxc_health + def main(): parser = argparse.ArgumentParser(description="System Health Monitor") parser.add_argument(