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