Last active
August 26, 2024 04:14
-
-
Save walm/e084e5184bc14da9ddbe to your computer and use it in GitHub Desktop.
Simple Linux Server stats as JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
echo -n '{' | |
# memory as "mem": { "current": 800, "total": 1024, "load", 82 } where amount is in MB and load in % | |
free -m | awk 'NR==2{printf "\"mem\": { \"current\":%d, \"total\":%d, \"load\": %.2f }", $3,$2,$3*100/$2 }' | |
echo -n ',' | |
# diska as "disk": { "current": 6, "total": 40, "used": 19 } where amount is in GB and used in % | |
df -h | awk '$NF=="/"{printf "\"disk\": { \"current\":%d, \"total\":%d, \"used\": %d }", $3,$2,$5}' | |
echo -n ',' | |
# cpu as "cpu": { "load": 40 } where load is in % | |
top -bn1 | grep load | awk '{printf "\"cpu\": { \"load\": %.2f }", $(NF-2)}' | |
echo -n '}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cpu" : { | |
"load" : 0 | |
}, | |
"disk" : { | |
"used" : 19, | |
"current" : 6, | |
"total" : 40 | |
}, | |
"mem" : { | |
"current" : 1814, | |
"load" : 90.61, | |
"total" : 2002 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks!