drive parition info

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

View File

@ -119,6 +119,9 @@ class SystemHealthMonitor:
for drive in health_report['drives_health']['drives']: for drive in health_report['drives_health']['drives']:
temp_str = f", Temp: {drive.get('temperature')}°C" if drive.get('temperature') else "" 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']}") 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 Status: {health_report['memory_health']['status']}")
logger.info(f"Memory Usage: {health_report['memory_health']['memory_percent']}%") logger.info(f"Memory Usage: {health_report['memory_health']['memory_percent']}%")
@ -871,9 +874,6 @@ class SystemHealthMonitor:
return smart_health return smart_health
def _check_drives_health(self) -> Dict[str, Any]: 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': []} drives_health = {'overall_status': 'NORMAL', 'drives': []}
try: try:
@ -882,36 +882,47 @@ class SystemHealthMonitor:
if disk.startswith(('/dev/sd', '/dev/nvme'))] if disk.startswith(('/dev/sd', '/dev/nvme'))]
logger.debug(f"Checking physical disks: {physical_disks}") logger.debug(f"Checking physical disks: {physical_disks}")
# Get partition information # Get ALL partition information including device mapper
partitions = psutil.disk_partitions(all=True) 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' overall_status = 'NORMAL'
for disk in physical_disks: for disk in physical_disks:
drive_report = { drive_report = {
'device': disk, 'device': disk,
'mountpoint': None, 'partitions': [],
'usage_status': 'UNMOUNTED',
'usage_percent': 0,
'total_space': '0B',
'used_space': '0B',
'free_space': '0B',
'smart_status': 'UNKNOWN' 'smart_status': 'UNKNOWN'
} }
mountpoint = disk_to_mount.get(disk) # Add partition information if available
# Get disk usage if mounted if disk in device_partitions:
if mountpoint: for partition in device_partitions[disk]:
usage = psutil.disk_usage(mountpoint) try:
drive_report.update({ usage = psutil.disk_usage(partition.mountpoint)
'usage_status': 'MOUNTED', part_info = {
'usage_percent': usage.percent, 'device': partition.device,
'total_space': self._convert_bytes(usage.total), 'mountpoint': partition.mountpoint,
'used_space': self._convert_bytes(usage.used), 'fstype': partition.fstype,
'free_space': self._convert_bytes(usage.free) '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) smart_health = self._check_smart_health(disk)
drive_report.update({ drive_report.update({
'smart_status': smart_health['status'], 'smart_status': smart_health['status'],
@ -920,7 +931,6 @@ class SystemHealthMonitor:
'smart_attributes': smart_health['attributes'] 'smart_attributes': smart_health['attributes']
}) })
# Update overall status based on SMART health
if smart_health['status'] == 'UNHEALTHY': if smart_health['status'] == 'UNHEALTHY':
overall_status = 'CRITICAL' overall_status = 'CRITICAL'
elif smart_health['issues'] and overall_status != 'CRITICAL': elif smart_health['issues'] and overall_status != 'CRITICAL':