From 09006c4d635ccfea8670e2c159a804a738728dee Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 4 Oct 2026 22:53:08 +0000 Subject: [PATCH] Add collector.py --- collector.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 collector.py diff --git a/collector.py b/collector.py new file mode 100644 index 0000000..a478afc --- /dev/null +++ b/collector.py @@ -0,0 +1,25 @@ +#!/bin/python3 + +import os +import json +import socket +from datetime import datetime, timezone +import psutil + + +data = { + "hostname": socket.gethostname(), + "timestamp": datetime.now(timezone.utc).isoformat(), + "uptime": os.popen("uptime -p").read().strip(), + "cpu_count": psutil.cpu_count(), + "cpu_usage": psutil.cpu_percent(), + "ram_total_gb": round(psutil.virtual_memory().total / 1024**3, 2), + "ram_usage": psutil.virtual_memory().percent, + "swap_total_gb": round(psutil.swap_memory().total / 1024**3, 2), + "swap_usage": psutil.swap_memory().percent, + "disk_total_gb": round(psutil.disk_usage("/").total / 1024**3, 2), + "disk_usage": psutil.disk_usage("/").percent +} + +with open("/home/myguy/stats.json", "w") as f: + json.dump(data, f, indent=4) \ No newline at end of file