Created
July 16, 2018 02:50
-
-
Save rkJun/1031ca2a01dfe8b26fb3620bb0482efe to your computer and use it in GitHub Desktop.
Server Health Checker (Memory, Disk, CPU) and send to slack
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/bash | |
freeText=$(free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }') | |
diskText=$(df -h | awk '$NF=="/"{printf "Disk Usage: %d/%dGB (%s)\n", $3,$2,$5}') | |
cpuText=$(top -bn1 | grep load | awk '{printf "CPU Load: %.2f\n", $(NF-2)}') | |
resultText=$(echo 'ServerName ('${HOSTNAME}')' ${cpuText} ${freeText} ${diskText}) | |
echo $resultText | |
curl 'https://hooks.slack.com/services/...blah...blah..webhook.url' \ | |
-X POST -H 'Content-type: application/json' \ | |
--data @<(cat <<EOF | |
{ | |
"text": "$resultText" | |
} | |
EOF | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment