Created
December 3, 2020 09:54
-
-
Save AronNovak/5fd4fc1cd49ecdf7fdde9e1b3b6a0d15 to your computer and use it in GitHub Desktop.
Memory low alert2slack
This file contains hidden or 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 | |
LANG=C | |
MINIMUM_REQUIRED_MEM=256 | |
FREE_MEM=$(free -mt | awk '/Total/{print $4}') | |
if [ $FREE_MEM -lt $MINIMUM_REQUIRED_MEM ]; then | |
TOP_PROCESS=$(ps aux --sort rss | tail -n1) | |
MESSAGE=$(echo "WARNING On $HOSTNAME, memory usage is low: $TOP_PROCESS WARNING" | sed 's/ /_/g') | |
# Post message | |
# @see https://api.slack.com/messaging/webhooks#create_a_webhook | |
curl -X POST --data-urlencode \ | |
'payload={"channel": "#sitehealth", "username": "webhookbot", "text": "'$MESSAGE'", "icon_emoji": ":ghost:"}' \ | |
https://hooks.slack.com/services/YourHook | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the system is really struggling, the script might not be able to do its job, that's right, so use with caution.