Skip to content

Instantly share code, notes, and snippets.

@rkJun
Created July 16, 2018 02:50
Show Gist options
  • Save rkJun/1031ca2a01dfe8b26fb3620bb0482efe to your computer and use it in GitHub Desktop.
Save rkJun/1031ca2a01dfe8b26fb3620bb0482efe 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
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