From d6d0f37c5aed73b51f4f8988c7bea65351076e5a Mon Sep 17 00:00:00 2001 From: oliver Date: Tue, 13 Oct 2026 20:00:20 -0300 Subject: [PATCH] works --- app/sbin/stats | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/sbin/stats b/app/sbin/stats index 3a26351..bcf9c96 100755 --- a/app/sbin/stats +++ b/app/sbin/stats @@ -1,7 +1,8 @@ #!/usr/bin/env python3 -"""Collect server runtime stats (uptime, top, cgroup, mounts) and return as JSON.""" +"""Collect server runtime stats (uptime, top, cgroup, mounts, hdd) and return as JSON.""" import json +import os import subprocess @@ -32,6 +33,20 @@ def read_file(path): return None +def disk_usage(path): + """Total/used/available bytes for the filesystem at `path` (same figures as df).""" + try: + st = os.statvfs(path) + return { + "path": path, + "total_bytes": st.f_blocks * st.f_frsize, + "used_bytes": (st.f_blocks - st.f_bfree) * st.f_frsize, + "available_bytes": st.f_bavail * st.f_frsize, + } + except Exception as e: + return f"ERROR: {e}" + + def main(): stats = {} @@ -39,6 +54,7 @@ def main(): stats["top"] = cmd(["sh", "-c", "top -b -n 1 | head -n 3"], splitlines=True) stats["cgroup"] = read_file("/proc/self/cgroup") stats["mounts"] = cmd(["mount"], splitlines=True) + stats["hdd"] = disk_usage("/") print(json.dumps(stats, indent=2))