parsing issue with fs

This commit is contained in:
2025-03-09 20:24:09 -04:00
parent d426557693
commit d9b3e62bb5

View File

@ -775,6 +775,43 @@ class SystemHealthMonitor:
if re.match(pattern, mountpoint): if re.match(pattern, mountpoint):
return True return True
return False return False
def _parse_size(self, size_str: str) -> float:
"""
Parse size string with units to bytes.
Examples: '1.5G', '500M', '2.3T', etc.
"""
if not size_str or not isinstance(size_str, str):
return 0.0
# Remove any spaces and convert to uppercase for consistency
size_str = size_str.strip().upper()
# Handle special case for MB notation
if 'MB' in size_str:
size_str = size_str.replace('MB', 'M')
# Define unit multipliers
units = {
'B': 1,
'K': 1024,
'M': 1024**2,
'G': 1024**3,
'T': 1024**4,
'P': 1024**5
}
try:
# Extract numeric value and unit
if size_str[-1] in units:
number = float(size_str[:-1])
unit = size_str[-1]
return number * units[unit]
# Handle case where the input is just a number
return float(size_str)
except (ValueError, IndexError):
logger.debug(f"Could not parse size: {size_str}")
return 0.0
def _is_physical_disk(self, device_path): def _is_physical_disk(self, device_path):
""" """
@ -1370,58 +1407,46 @@ class SystemHealthMonitor:
continue continue
logger.debug(f"Processing filesystem line: {fs_line}") logger.debug(f"Processing filesystem line: {fs_line}")
try: parts = fs_line.split()
parts = fs_line.split() if len(parts) >= 6:
if len(parts) >= 6: try:
usage_percent = 0 # Skip appPool entries and mediafs mounts
if parts[0].startswith('appPool:') or '/mnt/pve/mediaf' in parts[0]:
continue
filesystem = { filesystem = {
'mountpoint': parts[5], # Last column is the mountpoint 'mountpoint': parts[5],
'total': parts[2], # Size column 'total_space': parts[1], # Size
'used': parts[3], # Used column 'used_space': parts[2], # Used
'available': parts[4], # Avail column 'available': parts[3], # Avail
'usage_percent': float(parts[4].rstrip('%')) # Use% column 'usage_percent': float(parts[4].rstrip('%')) # Use%
} }
if parts[0].startswith('appPool:'):
logger.debug(f"Skipping appPool entry: {parts[0]}")
continue
if '/mnt/pve/mediaf' in parts[0]:
logger.debug(f"Skipping mediafs mount: {parts[0]}")
continue
mountpoint = parts[5]
logger.debug(f"Processing mountpoint: {mountpoint}")
if parts[1][-1] in 'BKMGT' and parts[2][-1] in 'BKMGT': # Convert sizes to bytes for comparison
total_size = self._convert_size_to_bytes(parts[1]) total_bytes = self._parse_size(filesystem['total_space'])
used_size = self._convert_size_to_bytes(parts[2]) used_bytes = self._parse_size(filesystem['used_space'])
usage_percent = float(parts[4].rstrip('%')) avail_bytes = self._parse_size(filesystem['available'])
logger.debug(f"Storage metrics parsed for LXC {vmid}:") # Store both human readable and byte values
logger.debug(f" Filesystem: {parts[0]}") filesystem['total_bytes'] = total_bytes
logger.debug(f" Total: {filesystem['total']}") filesystem['used_bytes'] = used_bytes
logger.debug(f" Used: {filesystem['used']}") filesystem['avail_bytes'] = avail_bytes
logger.debug(f" Available: {filesystem['available']}")
logger.debug(f" Usage: {usage_percent}%") if filesystem['usage_percent'] >= self.CONFIG['THRESHOLDS']['DISK_CRITICAL']:
logger.debug(f" Mountpoint: {filesystem['mountpoint']}")
if usage_percent >= self.CONFIG['THRESHOLDS']['DISK_CRITICAL']:
logger.debug(f"CRITICAL: Storage usage {usage_percent}% exceeds critical threshold")
lxc_health['status'] = 'CRITICAL' lxc_health['status'] = 'CRITICAL'
issue = f"LXC {vmid} critical storage usage: {usage_percent}% on {mountpoint}" issue = f"LXC {vmid} critical storage usage: {filesystem['usage_percent']}% on {filesystem['mountpoint']}"
lxc_health['issues'].append(issue) lxc_health['issues'].append(issue)
elif usage_percent >= self.CONFIG['THRESHOLDS']['DISK_WARNING']: elif filesystem['usage_percent'] >= self.CONFIG['THRESHOLDS']['DISK_WARNING']:
logger.debug(f"WARNING: Storage usage {usage_percent}% exceeds warning threshold")
if lxc_health['status'] != 'CRITICAL': if lxc_health['status'] != 'CRITICAL':
lxc_health['status'] = 'WARNING' lxc_health['status'] = 'WARNING'
issue = f"LXC {vmid} high storage usage: {usage_percent}% on {mountpoint}" issue = f"LXC {vmid} high storage usage: {filesystem['usage_percent']}% on {filesystem['mountpoint']}"
lxc_health['issues'].append(issue) lxc_health['issues'].append(issue)
container_info['filesystems'].append(filesystem) container_info['filesystems'].append(filesystem)
except Exception as e:
logger.debug(f"Error processing filesystem line for container {vmid}: {str(e)}") except Exception as e:
continue logger.debug(f"Error processing filesystem line for container {vmid}: {str(e)}")
continue
lxc_health['containers'].append(container_info) lxc_health['containers'].append(container_info)
logger.debug(f"Added container info for VMID {vmid}") logger.debug(f"Added container info for VMID {vmid}")