parsing issue with fs
This commit is contained in:
@ -776,6 +776,43 @@ class SystemHealthMonitor:
|
|||||||
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):
|
||||||
"""
|
"""
|
||||||
Check if the device is a physical disk, excluding logical volumes and special devices.
|
Check if the device is a physical disk, excluding logical volumes and special devices.
|
||||||
@ -1370,55 +1407,43 @@ 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:
|
||||||
usage_percent = 0
|
try:
|
||||||
|
# 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:'):
|
# Convert sizes to bytes for comparison
|
||||||
logger.debug(f"Skipping appPool entry: {parts[0]}")
|
total_bytes = self._parse_size(filesystem['total_space'])
|
||||||
continue
|
used_bytes = self._parse_size(filesystem['used_space'])
|
||||||
|
avail_bytes = self._parse_size(filesystem['available'])
|
||||||
|
|
||||||
if '/mnt/pve/mediaf' in parts[0]:
|
# Store both human readable and byte values
|
||||||
logger.debug(f"Skipping mediafs mount: {parts[0]}")
|
filesystem['total_bytes'] = total_bytes
|
||||||
continue
|
filesystem['used_bytes'] = used_bytes
|
||||||
|
filesystem['avail_bytes'] = avail_bytes
|
||||||
|
|
||||||
mountpoint = parts[5]
|
if filesystem['usage_percent'] >= self.CONFIG['THRESHOLDS']['DISK_CRITICAL']:
|
||||||
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")
|
|
||||||
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:
|
except Exception as e:
|
||||||
logger.debug(f"Error processing filesystem line for container {vmid}: {str(e)}")
|
logger.debug(f"Error processing filesystem line for container {vmid}: {str(e)}")
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user