Skip to content

Instantly share code, notes, and snippets.

@AronNovak
Created December 3, 2020 09:54
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 AronNovak/5fd4fc1cd49ecdf7fdde9e1b3b6a0d15 to your computer and use it in GitHub Desktop.
Save AronNovak/5fd4fc1cd49ecdf7fdde9e1b3b6a0d15 to your computer and use it in GitHub Desktop.
Memory low alert2slack
#!/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
@AronNovak
Copy link
Author

If the system is really struggling, the script might not be able to do its job, that's right, so use with caution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment