From e8c2bc4418fbe8646940433b45687151899be1b6 Mon Sep 17 00:00:00 2001 From: Xavier Date: Sat, 29 Aug 2026 11:11:24 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liorations=20BO2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/system_utils.py | 51 +++++++++++++++++++++++++++++++++------- modules/ui_components.py | 8 +++++-- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/modules/system_utils.py b/modules/system_utils.py index a56ead3..3a1fc40 100644 --- a/modules/system_utils.py +++ b/modules/system_utils.py @@ -1,21 +1,54 @@ import os import shutil import requests +import psutil def obtenir_infos_serveur(): # Espace disque racine / total, used, free = shutil.disk_usage("/") - # Espace disque /DATA (partition principale / RAID) + # Recherche intelligente de la partition RAID ou /DATA via psutil data_stats = {} - if os.path.exists("/DATA"): - dt, du, df = shutil.disk_usage("/DATA") - data_stats = { - "total_gb": round(dt / (2**30), 2), - "utilise_gb": round(du / (2**30), 2), - "libre_gb": round(df / (2**30), 2), - "pourcentage": round((du / dt) * 100, 1) - } + try: + partitions = psutil.disk_partitions(all=False) + for p in partitions: + # Priorité à la détection d'un périphérique md (RAID) ou du point de montage /DATA + if "md" in p.device or p.mountpoint == "/DATA": + try: + dt, du, df = shutil.disk_usage(p.mountpoint) + data_stats = { + "device": p.device, + "mountpoint": p.mountpoint, + "total_gb": round(dt / (2**30), 2), + "utilise_gb": round(du / (2**30), 2), + "libre_gb": round(df / (2**30), 2), + "pourcentage": round((du / dt) * 100, 1) + } + if "md" in p.device: + break # On privilégie en premier le RAID détecté + except Exception: + pass + + # Fallback sur /DATA si aucune détection spécifique md n'a eu lieu + if not data_stats and os.path.exists("/DATA"): + dt, du, df = shutil.disk_usage("/DATA") + data_stats = { + "device": "bind-mount /DATA", + "mountpoint": "/DATA", + "total_gb": round(dt / (2**30), 2), + "utilise_gb": round(du / (2**30), 2), + "libre_gb": round(df / (2**30), 2), + "pourcentage": round((du / dt) * 100, 1) + } + except Exception: + if os.path.exists("/DATA"): + dt, du, df = shutil.disk_usage("/DATA") + data_stats = { + "total_gb": round(dt / (2**30), 2), + "utilise_gb": round(du / (2**30), 2), + "libre_gb": round(df / (2**30), 2), + "pourcentage": round((du / dt) * 100, 1) + } # État du RAID logiciel (/proc/mdstat) raid_status = "RAID non actif ou non détecté" diff --git a/modules/ui_components.py b/modules/ui_components.py index 591e627..bb8c435 100644 --- a/modules/ui_components.py +++ b/modules/ui_components.py @@ -325,8 +325,12 @@ def render_backoffice_page(utilisateur, role, tous_les_utilisateurs, stats_serve sections.append(Div( H3("🖥️ Supervision Système, RAID & Agent Vectoriel", style="color: #ff9800;"), P(f"💾 Espace disque racine : {stats_serveur['disque_utilise_gb']} Go / {stats_serveur['disque_total_gb']} Go ({stats_serveur['pourcentage_utilise']}%)"), - (P(f"🗄️ Partition RAID (/DATA) : {data_st.get('utilise_gb', 0)} Go / {data_st.get('total_gb', 0)} Go ({data_st.get('pourcentage', 0)}% utilisés, {data_st.get('libre_gb', 0)} Go libres)") if data_st else P("🗄️ Partition RAID (/DATA) : Non montée ou non détectée")), - P(f"📡 État du RAID (mdstat) : {stats_serveur.get('raid_status', 'N/A')}", style="font-size: 0.85em; background: #222; padding: 8px; border-radius: 4px; white-space: pre-wrap;"), + (P(f"🗄️ Périphérique RAID ({data_st.get('device', '/DATA')} sur {data_st.get('mountpoint', '/DATA')}) : {data_st.get('utilise_gb', 0)} Go / {data_st.get('total_gb', 0)} Go ({data_st.get('pourcentage', 0)}% utilisés, {data_st.get('libre_gb', 0)} Go libres)") if data_st else P("🗄️ Partition RAID (/DATA) : Non montée ou non détectée")), + Div( + P("📡 État du RAID (mdstat) :", style="margin-bottom: 5px; font-weight: bold;"), + Pre(stats_serveur.get('raid_status', 'N/A'), style="font-size: 0.8em; background: #111; color: #00ffcc; padding: 10px; border-radius: 4px; overflow-x: auto; max-height: 180px; overflow-y: auto; white-space: pre-wrap; font-family: monospace; margin: 0;"), + style="margin-bottom: 15px;" + ), P(f"🤖 Agent Vectoriel (Ollama) : {stats_serveur.get('agent_status', 'N/A')}"), Hr(style="border-color: #444; margin: 15px 0;"), H4("⚡ Actions Globales RAG", style="color: #00e5ff; font-size: 1em;"),