lp-mu-ethernet-monitor.py

LattePanda Mu Ultra: x86 Compute Module for Embedded AI · File : lp-mu-ethernet-monitor.py · Language : python · Use case : Surveillance du trafic réseau sur l'interface Ethernet Intel I226-V.

Python script using psutil to monitor network throughput in real-time.

Install python3-psutil. Identify the exact Ethernet interface name (e.g., enp1s0) using 'ip addr'. This script displays cumulative sent/received bytes, useful for verifying the stability of the 2.5 Gbps link.

lp-mu-ethernet-monitor.py

import psutil
import time

INTERFACE = "enp1s0" # Nom de l'interface Ethernet Intel I226-V (vérifiez avec 'ip a')

def monitor_network():
    print(f"Surveillance de l'interface {INTERFACE}...")
    try:
        while True:
            # Statistiques agrégées depuis le démarrage
            stats = psutil.net_io_counters(pernic=True).get(INTERFACE)
            if stats:
                sent_mb = stats.bytes_sent / (1024 * 1024)
                recv_mb = stats.bytes_recv / (1024 * 1024)
                print(f"Sent: {sent_mb:.2f} MB | Recv: {recv_mb:.2f} MB", end="\r")
            else:
                print(f"Interface {INTERFACE} non trouvée.")
            time.sleep(1)
    except KeyboardInterrupt:
        print("\nArrêt de la surveillance.")

if __name__ == "__main__":
    monitor_network()

← Back to the board