x86-nvme-disk-health-monitor-10.ino

BIOSTAR EdgeComp MS-U320: Fanless Intel Wildcat Lake Industrial Mini PC · File : x86-nvme-disk-health-monitor-10.ino · Language : python · Use case : Surveiller l'intégrité et les températures du SSD NVMe M.2 via SMARTCTL.

Python monitor for SSD NVMe M.2 health, temperature, and ID via smartctl.

This script queries the M.2 NVMe controller via smartmontools. It extracts model, serial number, and crucially, temperature to prevent overheating in a fanless chassis. Run with root privileges (sudo python3 script.py) as smartctl requires device access. Install dependencies: sudo apt install smartmontools.

x86-nvme-disk-health-monitor-10.ino

import subprocess
import sys
import time

def get_ssd_info(device='/dev/nvme0'):
    """Récupère les infos SMART du SSD NVMe M.2."""
    try:
        # -a : toutes les infos, -x : format étendu
        result = subprocess.run(
            ['smartctl', '-a', device],
            capture_output=True,
            text=True,
            check=True
        )
        lines = result.stdout.split('\n')
        
        info = {
            'model': 'Unknown',
            'serial': 'Unknown',
            'health': 'Unknown',
            'temp': 'N/A'
        }
        
        for line in lines:
            if 'Model Number' in line:
                info['model'] = line.split(':', 1)[1].strip()
            elif 'Serial Number' in line:
                info['serial'] = line.split(':', 1)[1].strip()
            elif 'SMART overall-health' in line:
                info['health'] = line.split(':')[-1].strip()
            elif 'Temperature' in line and 'Celsius' in line:
                # Extraction simple de la température
                try:
                    parts = line.split(',')
                    for p in parts:
                        if 'Celsius' in p:
                            temp_val = p.split('(')[0].strip().split()[-1]
                            info['temp'] = f"{temp_val}°C"
                except:
                    pass
                    
        return info
    except subprocess.CalledProcessError as e:
        return None
    except FileNotFoundError:
        print("ERREUR: smartctl non installé. Installez 'smartmontools'.")
        sys.exit(1)

if __name__ == "__main__":
    # Ajustez le périphérique si le NVMe n'est pas nvme0
    SS_DEVICE = '/dev/nvme0'
    
    print(f"Vérification du stockage NVMe sur {SS_DEVICE}...")
    print("-" * 40)
    
    data = get_ssd_info(SS_DEVICE)
    
    if data:
        print(f"Modèle     : {data['model']}")
        print(f"Série      : {data['serial']}")
        print(f"Santé      : {data['health']}")
        print(f"Température: {data['temp']}")
        
        # Alerte température critique (>70°C pour un usage industriel continu)
        if data['temp'] != 'N/A':
            try:
                t = float(data['temp'].replace('°C', ''))
                if t > 70:
                    print("\n[ALERTE] Température SSD élevée ! Vérifiez le flux d'air.")
            except ValueError:
                pass
    else:
        print("Impossible de lire les données SMART. Vérifiez les permissions (sudo).")

← Back to the board