diff --git a/hwmonDaemon.py b/hwmonDaemon.py index f16f631..cb29167 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -811,8 +811,19 @@ class SystemHealthMonitor: } # Extract numeric value and unit - value = float(re.match(r'(\d+\.?\d*)', size_str).group(1)) - unit = re.search(r'([BKMGT])', size_str.upper()).group(1) + match = re.match(r'(\d+\.?\d*)', size_str) + if not match: + logger.debug(f"Could not extract numeric value from: {size_str}") + return 0.0 + + value = float(match.group(1)) + + unit_match = re.search(r'([BKMGT])', size_str.upper()) + if not unit_match: + logger.debug(f"Could not extract unit from: {size_str}") + return 0.0 + + unit = unit_match.group(1) logger.debug(f"Extracted value: {value}, unit: {unit}") @@ -1426,27 +1437,48 @@ class SystemHealthMonitor: logger.debug(f"Split parts: {parts}") if len(parts) >= 6: try: + # Skip excluded mounts if parts[0].startswith('appPool:') or '/mnt/pve/mediaf' in parts[0]: continue + # Get the mountpoint (last column) + mountpoint = parts[5] if len(parts) > 5 else "/" + + # Skip excluded mountpoints + if self._is_excluded_mount(mountpoint): + logger.debug(f"Skipping excluded mount: {mountpoint}") + continue + + # Parse size values safely + total_space = self._parse_size(parts[1]) + used_space = self._parse_size(parts[2]) + available_space = self._parse_size(parts[3]) + + # Parse percentage safely + try: + usage_percent = float(parts[4].rstrip('%')) + except (ValueError, IndexError): + # Calculate percentage if parsing fails + usage_percent = (used_space / total_space * 100) if total_space > 0 else 0 + filesystem = { - 'mountpoint': parts[5], - 'total_space': self._parse_size(parts[1]), # Convert size to bytes - 'used_space': self._parse_size(parts[2]), # Convert used to bytes - 'available': self._parse_size(parts[3]), # Convert available to bytes - 'usage_percent': float(parts[4].rstrip('%')) # Use percentage as is + 'mountpoint': mountpoint, + 'total_space': total_space, + 'used_space': used_space, + 'available': available_space, + 'usage_percent': usage_percent } container_info['filesystems'].append(filesystem) # Check thresholds - if filesystem['usage_percent'] >= self.CONFIG['THRESHOLDS']['LXC_CRITICAL']: + if usage_percent >= self.CONFIG['THRESHOLDS']['LXC_CRITICAL']: lxc_health['status'] = 'CRITICAL' - issue = f"LXC {vmid} critical storage usage: {filesystem['usage_percent']}% on {filesystem['mountpoint']}" + issue = f"LXC {vmid} critical storage usage: {usage_percent:.1f}% on {mountpoint}" lxc_health['issues'].append(issue) - elif filesystem['usage_percent'] >= self.CONFIG['THRESHOLDS']['LXC_WARNING']: + elif usage_percent >= self.CONFIG['THRESHOLDS']['LXC_WARNING']: if lxc_health['status'] != 'CRITICAL': lxc_health['status'] = 'WARNING' - issue = f"LXC {vmid} high storage usage: {filesystem['usage_percent']}% on {filesystem['mountpoint']}" + issue = f"LXC {vmid} high storage usage: {usage_percent:.1f}% on {mountpoint}" lxc_health['issues'].append(issue) logger.debug(f"Filesystem details: {filesystem}") @@ -1454,8 +1486,11 @@ class SystemHealthMonitor: logger.debug(f"Error processing line: {str(e)}") logger.debug(f"Full exception: {repr(e)}") continue - lxc_health['containers'].append(container_info) - logger.debug(f"Added container info for VMID {vmid}") + + # Only add container info if we have filesystem data + if container_info['filesystems']: + lxc_health['containers'].append(container_info) + logger.debug(f"Added container info for VMID {vmid}") logger.debug("=== LXC Storage Check Summary ===") logger.debug(f"Status: {lxc_health['status']}")