Feature: Disk Usage via df im Dashboard (LXC-kompatibel)
- get_disk_usage() in system_info.py via /usr/bin/df -P - GET /api/system/disk-usage Endpoint - getDiskUsage() im API-Client - Dashboard zeigt Disk Usage Karten mit Balken + Total/Used/Free (sichtbar auf LXC wo /proc/diskstats keine Blockgeräte liefert) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -168,7 +168,16 @@ async def get_network_traffic():
|
||||
return result
|
||||
|
||||
|
||||
# ============== DISK I/O ==============
|
||||
# ============== DISK USAGE + I/O ==============
|
||||
|
||||
@router.get("/disk-usage")
|
||||
async def get_disk_usage():
|
||||
"""Get filesystem disk usage from df (public)"""
|
||||
result = system_info.get_disk_usage()
|
||||
if "error" in result:
|
||||
raise HTTPException(status_code=500, detail=result["error"])
|
||||
return result
|
||||
|
||||
|
||||
@router.get("/diskio")
|
||||
async def get_diskio():
|
||||
|
||||
@@ -429,6 +429,42 @@ def get_all_units() -> Dict[str, Any]:
|
||||
return {"error": str(e)}
|
||||
|
||||
|
||||
def get_disk_usage() -> Dict[str, Any]:
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["/usr/bin/df", "-P", "-x", "tmpfs", "-x", "devtmpfs", "-x", "squashfs", "-x", "overlay"],
|
||||
capture_output=True, text=True, timeout=5
|
||||
)
|
||||
if result.returncode != 0:
|
||||
return {"error": result.stderr}
|
||||
|
||||
filesystems = []
|
||||
for line in result.stdout.strip().split("\n")[1:]:
|
||||
parts = line.split()
|
||||
if len(parts) < 6:
|
||||
continue
|
||||
try:
|
||||
total = int(parts[1]) * 1024
|
||||
used = int(parts[2]) * 1024
|
||||
available = int(parts[3]) * 1024
|
||||
capacity = int(parts[4].rstrip("%"))
|
||||
filesystems.append({
|
||||
"filesystem": parts[0],
|
||||
"mountpoint": parts[5],
|
||||
"total": total,
|
||||
"used": used,
|
||||
"available": available,
|
||||
"capacity": capacity,
|
||||
})
|
||||
except (ValueError, IndexError):
|
||||
continue
|
||||
|
||||
return {"filesystems": filesystems}
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting disk usage: {e}")
|
||||
return {"error": str(e)}
|
||||
|
||||
|
||||
def get_journal_logs(limit: int = 20) -> Dict[str, Any]:
|
||||
try:
|
||||
result = subprocess.run(
|
||||
|
||||
Reference in New Issue
Block a user