Added manufacturer and better nvme temp support

This commit is contained in:
2025-03-03 19:54:52 -05:00
parent 8980022959
commit afa338f4cf

View File

@ -576,7 +576,8 @@ class SystemHealthMonitor:
r'/dev/loop', # Loop devices r'/dev/loop', # Loop devices
r'/dev/rbd', # Ceph RBD devices r'/dev/rbd', # Ceph RBD devices
r'/boot', # Boot partitions r'/boot', # Boot partitions
r'/boot/efi' # EFI partitions r'/boot/efi', # EFI partitions
r'[0-9]+$' # Partition numbers
] ]
if any(re.search(pattern, device_path) for pattern in excluded_patterns): if any(re.search(pattern, device_path) for pattern in excluded_patterns):
@ -607,6 +608,15 @@ class SystemHealthMonitor:
'is_problematic': False, 'is_problematic': False,
'known_issues': [] 'known_issues': []
} }
MANUFACTURER_PATTERNS = {
'Western Digital': ['WDC', 'Western Digital', 'Ultrastar'],
'Samsung': ['Samsung', 'SAMSUNG'],
'Seagate': ['Seagate', 'ST'],
'Intel': ['Intel', 'INTEL'],
'Micron': ['Micron', 'Crucial'],
'Toshiba': ['Toshiba', 'TOSHIBA']
}
try: try:
result = subprocess.run( result = subprocess.run(
@ -616,20 +626,23 @@ class SystemHealthMonitor:
text=True text=True
) )
model_line = None
for line in result.stdout.split('\n'): for line in result.stdout.split('\n'):
if 'Firmware Version:' in line: if 'Firmware Version:' in line:
firmware_info['version'] = line.split(':')[1].strip() firmware_info['version'] = line.split(':')[1].strip()
elif 'Model Family:' in line: elif 'Model Family:' in line:
model_line = line
firmware_info['model'] = line.split(':')[1].strip()
elif 'Device Model:' in line and not firmware_info['model']:
model_line = line
firmware_info['model'] = line.split(':')[1].strip() firmware_info['model'] = line.split(':')[1].strip()
elif 'Device Model:' in line:
if not firmware_info['model']:
firmware_info['model'] = line.split(':')[1].strip()
# Determine manufacturer # Determine manufacturer
for manufacturer in self.PROBLEMATIC_FIRMWARE.keys(): if model_line:
if manufacturer in firmware_info['model']: for manufacturer, patterns in MANUFACTURER_PATTERNS.items():
firmware_info['manufacturer'] = manufacturer if any(pattern in model_line for pattern in patterns):
break firmware_info['manufacturer'] = manufacturer
break
# Check against known problematic versions # Check against known problematic versions
if firmware_info['manufacturer'] and firmware_info['model']: if firmware_info['manufacturer'] and firmware_info['model']:
@ -812,7 +825,20 @@ class SystemHealthMonitor:
logger.debug(f"{attr}: {value}") logger.debug(f"{attr}: {value}")
logger.debug(f"Temperature: {smart_health['temp']}°C") logger.debug(f"Temperature: {smart_health['temp']}°C")
logger.debug(f"Detected Issues: {smart_health['issues']}") logger.debug(f"Detected Issues: {smart_health['issues']}")
logger.debug("=== End SMART Check ===\n") logger.debug("=== End SMART Check ===\n")
# Special handling for NVMe drives
if 'nvme' in device:
nvme_result = subprocess.run(
['nvme', 'smart-log', device],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
for line in nvme_result.stdout.split('\n'):
if 'temperature' in line.lower():
smart_health['temp'] = int(line.split(':')[1].strip().split()[0])
break
except Exception as e: except Exception as e:
smart_health['status'] = 'ERROR' smart_health['status'] = 'ERROR'
@ -828,11 +854,15 @@ class SystemHealthMonitor:
drives_health = {'overall_status': 'NORMAL', 'drives': []} drives_health = {'overall_status': 'NORMAL', 'drives': []}
try: try:
# Get physical disks only (exclude RBD devices) # Get physical disks only
physical_disks = [disk for disk in self._get_all_disks() physical_disks = [disk for disk in self._get_all_disks()
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
partitions = psutil.disk_partitions(all=True)
disk_to_mount = {part.device: part.mountpoint for part in partitions}
overall_status = 'NORMAL' overall_status = 'NORMAL'
for disk in physical_disks: for disk in physical_disks:
drive_report = { drive_report = {
@ -846,6 +876,17 @@ class SystemHealthMonitor:
'smart_status': 'UNKNOWN' 'smart_status': 'UNKNOWN'
} }
# 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)
})
# Check SMART health first # Check SMART health first
smart_health = self._check_smart_health(disk) smart_health = self._check_smart_health(disk)
drive_report.update({ drive_report.update({