22 lines
803 B
Python
22 lines
803 B
Python
#!/usr/bin/env python3
|
|
"""Quick disk usage checker - returns JSON for easy parsing."""
|
|
import json
|
|
import shutil
|
|
|
|
def get_disk_usage():
|
|
"""Get disk usage for root partition."""
|
|
total, used, free = shutil.disk_usage("/")
|
|
return {
|
|
"partition": "/",
|
|
"total_gb": round(total / (1024**3), 2),
|
|
"used_gb": round(used / (1024**3), 2),
|
|
"free_gb": round(free / (1024**3), 2),
|
|
"percent_used": round((used / total) * 100, 1),
|
|
"status": "ok" if (used / total) < 0.8 else "warning" if (used / total) < 0.9 else "critical"
|
|
}
|
|
|
|
if __name__ == "__main__":
|
|
result = get_disk_usage()
|
|
print(json.dumps(result, indent=2))
|
|
# Exit with special code based on status
|
|
exit(0 if result["status"] == "ok" else 2 if result["status"] == "warning" else 3) |