This commit is contained in:
oliver committed 2026-10-13 20:00:20 -03:00
1 parent 9b02a488bf
commit d6d0f37c5a
1 file changed
+17 -1
+17 -1
View File
@@ -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))