Files
aethas-free/modules/system_utils.py
T
xavier e8c2bc4418
Build and Push Docker Image / build-and-push (push) Successful in 35s
Améliorations BO2
2026-08-29 11:11:24 +02:00

81 lines
3.1 KiB
Python

import os
import shutil
import requests
import psutil
def obtenir_infos_serveur():
# Espace disque racine /
total, used, free = shutil.disk_usage("/")
# Recherche intelligente de la partition RAID ou /DATA via psutil
data_stats = {}
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é"
if os.path.exists("/proc/mdstat"):
try:
with open("/proc/mdstat", "r") as f:
raid_status = f.read().strip()
except Exception as e:
raid_status = f"Erreur de lecture mdstat : {e}"
# État de l'Agent Vectoriel (Ollama)
agent_status = "Injoignable"
try:
resp = requests.get("http://172.19.0.1:11434/api/tags", timeout=2)
if resp.status_code == 200:
agent_status = "Actif (Ollama & Embeddings en ligne)"
else:
agent_status = f"Répond (Code HTTP {resp.status_code})"
except Exception:
agent_status = "Hors ligne / Injoignable"
return {
"disque_total_gb": round(total / (2**30), 2),
"disque_utilise_gb": round(used / (2**30), 2),
"disque_libre_gb": round(free / (2**30), 2),
"pourcentage_utilise": round((used / total) * 100, 1),
"data_stats": data_stats,
"raid_status": raid_status,
"agent_status": agent_status
}