From cc7d719465597bdf71b43a9260437f83724e3087 Mon Sep 17 00:00:00 2001 From: nessi Date: Sun, 16 Aug 2026 12:32:08 +0200 Subject: [PATCH] feat: add system load average, uptime, and process count to dashboard with responsive detail cards and iconify indicators Add os.getloadavg() to system_metrics() with (0,0,0) fallback for AttributeError/OSError. Add /proc/uptime parsing for uptime_seconds with float conversion and 0 fallback. Add /proc process counting by iterating numeric entries with OSError exception handling. Add load/uptime_seconds/processes fields to /api/system response with rounded values. Add DOMContentLoaded script to inject # --- app.py | 14 +++++++++++++- templates/index.html | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index e2f8cfd..cdcc24d 100644 --- a/app.py +++ b/app.py @@ -491,7 +491,19 @@ def system_metrics(): disks.append({"label": label, "path": path, "total": format_bytes(usage.total), "used": format_bytes(usage.used), "free": format_bytes(usage.free), "used_bytes": usage.used, "total_bytes": usage.total, "percent": round(usage.used / usage.total * 100, 1) if usage.total else 0}) except OSError: continue - return {"cpu_percent": cpu_usage_percent(), "memory": {"used": format_bytes(used_memory), "total": format_bytes(total_memory), "percent": round(used_memory / total_memory * 100, 1) if total_memory else 0}, "disks": disks, "timestamp": time.time()} + try: + load = os.getloadavg() + except (AttributeError, OSError): + load = (0, 0, 0) + try: + uptime_seconds = float(Path("/proc/uptime").read_text().split()[0]) + except (OSError, ValueError, IndexError): + uptime_seconds = 0 + try: + process_count = sum(1 for entry in Path("/proc").iterdir() if entry.name.isdigit()) + except OSError: + process_count = 0 + return {"cpu_percent": cpu_usage_percent(), "memory": {"used": format_bytes(used_memory), "total": format_bytes(total_memory), "percent": round(used_memory / total_memory * 100, 1) if total_memory else 0}, "disks": disks, "load": [round(value, 2) for value in load], "uptime_seconds": round(uptime_seconds), "processes": process_count, "timestamp": time.time()} def release_languages(name): value = f" {name.lower().replace('.', ' ').replace('-', ' ')} " diff --git a/templates/index.html b/templates/index.html index 889078b..c717e2c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,4 +1,6 @@ + +