Skip to content

Instantly share code, notes, and snippets.

@fekberg
Last active December 20, 2015 16:09
Show Gist options
  • Select an option

  • Save fekberg/6159499 to your computer and use it in GitHub Desktop.

Select an option

Save fekberg/6159499 to your computer and use it in GitHub Desktop.
Shell script used to increase/decrease memory on my server
#!/bin/bash
# This cronjob runs at least once a minute and will check if the usage of RAM is more than 75%
# if it is more than 75% it sends me an e-mail and invokes the API. API call removed from the example.
# When the percentage left after a possible decrease is 70& then it decreases the RAM to that level
TOTAL=`free | grep Mem: | awk '{print $2}'`
USED=`free | grep Mem: | awk '{print $3}'`
INCREASE=$(((TOTAL/1024)+512));
DECREASE=$(((TOTAL/1024)-512));
PERCENTAGE=$(((USED*100)/TOTAL));
PERCENTAGE_DECREASE=$(((USED*100)/(DECREASE*1024)));
if [ $PERCENTAGE -gt 75 ]; then
if [ $INCREASE -lt 10000 ]; then
# Send e-mail about increasing memory
# Invoke API to increase memory
fi;
elif [ $PERCENTAGE_DECREASE -lt 70 ]; then
if [ $DECREASE -gt 768 ]; then
# Send e-mail about decreasing memory
# Invoke API to decrease memory
fi
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment