drive parition info

This commit is contained in:
2025-03-03 20:46:43 -05:00
parent 8186aa45dd
commit 6e3d537119

View File

@ -119,7 +119,10 @@ class SystemHealthMonitor:
for drive in health_report['drives_health']['drives']:
temp_str = f", Temp: {drive.get('temperature')}°C" if drive.get('temperature') else ""
logger.info(f"Drive {drive['device']}{temp_str}: {drive.get('usage_percent', 0)}% used, SMART: {drive['smart_status']}")
for partition in drive.get('partitions', []):
logger.info(f" └─ {partition['device']} mounted on {partition['mountpoint']}")
logger.info(f" {partition['used_space']}/{partition['total_space']} ({partition['usage_percent']}% used)")
logger.info(f"Memory Status: {health_report['memory_health']['status']}")
logger.info(f"Memory Usage: {health_report['memory_health']['memory_percent']}%")
logger.info(f"ECC Memory: {'Present' if health_report['memory_health']['has_ecc'] else 'Not Present'}")
@ -871,9 +874,6 @@ class SystemHealthMonitor:
return smart_health
def _check_drives_health(self) -> Dict[str, Any]:
"""
Check overall health of physical SATA and NVMe drives including disk usage and SMART status.
"""
drives_health = {'overall_status': 'NORMAL', 'drives': []}
try:
@ -882,36 +882,47 @@ class SystemHealthMonitor:
if disk.startswith(('/dev/sd', '/dev/nvme'))]
logger.debug(f"Checking physical disks: {physical_disks}")
# Get partition information
# Get ALL partition information including device mapper
partitions = psutil.disk_partitions(all=True)
disk_to_mount = {part.device: part.mountpoint for part in partitions}
# Create mapping of base devices to their partitions
device_partitions = {}
for part in partitions:
# Extract base device (e.g., /dev/sda from /dev/sda1)
base_device = re.match(r'(/dev/[a-z]+)', part.device)
if base_device:
base_dev = base_device.group(1)
if base_dev not in device_partitions:
device_partitions[base_dev] = []
device_partitions[base_dev].append(part)
overall_status = 'NORMAL'
for disk in physical_disks:
drive_report = {
'device': disk,
'mountpoint': None,
'usage_status': 'UNMOUNTED',
'usage_percent': 0,
'total_space': '0B',
'used_space': '0B',
'free_space': '0B',
'partitions': [],
'smart_status': 'UNKNOWN'
}
mountpoint = disk_to_mount.get(disk)
# Get disk usage if mounted
if mountpoint:
usage = psutil.disk_usage(mountpoint)
drive_report.update({
'usage_status': 'MOUNTED',
'usage_percent': usage.percent,
'total_space': self._convert_bytes(usage.total),
'used_space': self._convert_bytes(usage.used),
'free_space': self._convert_bytes(usage.free)
})
# Add partition information if available
if disk in device_partitions:
for partition in device_partitions[disk]:
try:
usage = psutil.disk_usage(partition.mountpoint)
part_info = {
'device': partition.device,
'mountpoint': partition.mountpoint,
'fstype': partition.fstype,
'total_space': self._convert_bytes(usage.total),
'used_space': self._convert_bytes(usage.used),
'free_space': self._convert_bytes(usage.free),
'usage_percent': usage.percent
}
drive_report['partitions'].append(part_info)
except Exception as e:
logger.debug(f"Error getting partition usage for {partition.device}: {e}")
# Check SMART health first
# Check SMART health
smart_health = self._check_smart_health(disk)
drive_report.update({
'smart_status': smart_health['status'],
@ -920,7 +931,6 @@ class SystemHealthMonitor:
'smart_attributes': smart_health['attributes']
})
# Update overall status based on SMART health
if smart_health['status'] == 'UNHEALTHY':
overall_status = 'CRITICAL'
elif smart_health['issues'] and overall_status != 'CRITICAL':