Public Access
76 lines
2.7 KiB
Python
76 lines
2.7 KiB
Python
import os
|
|
import shutil
|
|
import requests
|
|
import psutil
|
|
|
|
def obtenir_infos_serveur():
|
|
# Espace disque racine /
|
|
total, used, free = shutil.disk_usage("/")
|
|
|
|
# Recherche spécifique de la partition RAID /DATA ou du périphérique md
|
|
data_stats = {}
|
|
try:
|
|
partitions = psutil.disk_partitions(all=True)
|
|
point_montage_cible = None
|
|
|
|
# On cherche en priorité un montage sur /DATA ou un device contenant 'md'
|
|
for p in partitions:
|
|
if p.mountpoint == "/DATA" or "md" in p.device:
|
|
point_montage_cible = p.mountpoint
|
|
break
|
|
|
|
if point_montage_cible:
|
|
dt, du, df = shutil.disk_usage(point_montage_cible)
|
|
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)
|
|
}
|
|
elif 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)
|
|
}
|
|
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
|
|
} |