parsing issue with fs
This commit is contained in:
105
hwmonDaemon.py
105
hwmonDaemon.py
@ -776,6 +776,43 @@ class SystemHealthMonitor:
|
||||
return True
|
||||
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):
|
||||
"""
|
||||
Check if the device is a physical disk, excluding logical volumes and special devices.
|
||||
@ -1370,58 +1407,46 @@ class SystemHealthMonitor:
|
||||
continue
|
||||
|
||||
logger.debug(f"Processing filesystem line: {fs_line}")
|
||||
try:
|
||||
parts = fs_line.split()
|
||||
if len(parts) >= 6:
|
||||
usage_percent = 0
|
||||
parts = fs_line.split()
|
||||
if len(parts) >= 6:
|
||||
try:
|
||||
# Skip appPool entries and mediafs mounts
|
||||
if parts[0].startswith('appPool:') or '/mnt/pve/mediaf' in parts[0]:
|
||||
continue
|
||||
|
||||
filesystem = {
|
||||
'mountpoint': parts[5], # Last column is the mountpoint
|
||||
'total': parts[2], # Size column
|
||||
'used': parts[3], # Used column
|
||||
'available': parts[4], # Avail column
|
||||
'usage_percent': float(parts[4].rstrip('%')) # Use% column
|
||||
'mountpoint': parts[5],
|
||||
'total_space': parts[1], # Size
|
||||
'used_space': parts[2], # Used
|
||||
'available': parts[3], # Avail
|
||||
'usage_percent': float(parts[4].rstrip('%')) # Use%
|
||||
}
|
||||
|
||||
if parts[0].startswith('appPool:'):
|
||||
logger.debug(f"Skipping appPool entry: {parts[0]}")
|
||||
continue
|
||||
# Convert sizes to bytes for comparison
|
||||
total_bytes = self._parse_size(filesystem['total_space'])
|
||||
used_bytes = self._parse_size(filesystem['used_space'])
|
||||
avail_bytes = self._parse_size(filesystem['available'])
|
||||
|
||||
if '/mnt/pve/mediaf' in parts[0]:
|
||||
logger.debug(f"Skipping mediafs mount: {parts[0]}")
|
||||
continue
|
||||
# Store both human readable and byte values
|
||||
filesystem['total_bytes'] = total_bytes
|
||||
filesystem['used_bytes'] = used_bytes
|
||||
filesystem['avail_bytes'] = avail_bytes
|
||||
|
||||
mountpoint = parts[5]
|
||||
logger.debug(f"Processing mountpoint: {mountpoint}")
|
||||
|
||||
if parts[1][-1] in 'BKMGT' and parts[2][-1] in 'BKMGT':
|
||||
total_size = self._convert_size_to_bytes(parts[1])
|
||||
used_size = self._convert_size_to_bytes(parts[2])
|
||||
usage_percent = float(parts[4].rstrip('%'))
|
||||
|
||||
logger.debug(f"Storage metrics parsed for LXC {vmid}:")
|
||||
logger.debug(f" Filesystem: {parts[0]}")
|
||||
logger.debug(f" Total: {filesystem['total']}")
|
||||
logger.debug(f" Used: {filesystem['used']}")
|
||||
logger.debug(f" Available: {filesystem['available']}")
|
||||
logger.debug(f" Usage: {usage_percent}%")
|
||||
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")
|
||||
if filesystem['usage_percent'] >= self.CONFIG['THRESHOLDS']['DISK_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)
|
||||
elif usage_percent >= self.CONFIG['THRESHOLDS']['DISK_WARNING']:
|
||||
logger.debug(f"WARNING: Storage usage {usage_percent}% exceeds warning threshold")
|
||||
elif filesystem['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 {mountpoint}"
|
||||
issue = f"LXC {vmid} high storage usage: {filesystem['usage_percent']}% on {filesystem['mountpoint']}"
|
||||
lxc_health['issues'].append(issue)
|
||||
|
||||
container_info['filesystems'].append(filesystem)
|
||||
except Exception as e:
|
||||
logger.debug(f"Error processing filesystem line for container {vmid}: {str(e)}")
|
||||
continue
|
||||
|
||||
except Exception as e:
|
||||
logger.debug(f"Error processing filesystem line for container {vmid}: {str(e)}")
|
||||
continue
|
||||
|
||||
lxc_health['containers'].append(container_info)
|
||||
logger.debug(f"Added container info for VMID {vmid}")
|
||||
|
||||
Reference in New Issue
Block a user