Skip to content

Instantly share code, notes, and snippets.

@rkJun
Last active July 16, 2018 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkJun/b467dbd2f40aa11596a72839034ccc2d to your computer and use it in GitHub Desktop.
Save rkJun/b467dbd2f40aa11596a72839034ccc2d to your computer and use it in GitHub Desktop.
Server Health Checker (Memory, Disk, CPU) and send to slack
#!/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