25 lines
780 B
Python
25 lines
780 B
Python
#!/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) |