Last active
July 16, 2018 02:53
-
-
Save rkJun/b467dbd2f40aa11596a72839034ccc2d 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 | |
#ServerName (precise64) CPU Load: 0.00 Memory Usage: 315/363MB (86.78%) Disk Usage: 1/78GB (3%) | |
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