Created
August 9, 2012 10:27
-
-
Save jakubjedelsky/3303063 to your computer and use it in GitHub Desktop.
Memory leak keeper
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 | |
# | |
# Memory leak keeper | |
# | |
# simple log | |
LOG_FILE='/dev/stdout' | |
# system info, can be $LOG_FILE | |
COL_FILE=$LOG_FILE | |
# mem limit in percent | |
MEM_LIMIT='90' | |
# running | |
RUN_FILE='/tmp/check_mem' | |
function get_data { | |
# uncommecnt or add what you need | |
ps -eo pcpu,pmem,pid,user,args >> $COL_FILE | |
#/etc/init.d/httpd fullstatus >> $COL_FILE | |
#mysqladmin proc >> $COL_FILE | |
} | |
function restart_services { | |
# uncomment or add what you need | |
#/etc/init.d/httpd restart >> $COL_FILE | |
#/etc/init.d/mysqld restart >> $COL_FILE | |
#/etc/init.d/dovecot restart >> $COL_FILE | |
#/etc/init.d/amavisd restart >> $COL_FILE | |
return 0 | |
} | |
if [ -e $RUN_FILE ] ; then | |
exit 1 | |
fi | |
touch $RUN_FILE | |
mem=`/usr/bin/free | grep "Mem:"` | |
max_mem=`echo $mem | awk '{print $2}'` | |
curr_mem=`echo $mem | awk '{print $3}'` | |
p_mem=$((($curr_mem*100)/$max_mem)) | |
if [ $p_mem -gt $MEM_LIMIT ] ; then | |
echo "[`date +'%F %R'`] mem is out of interval - $p_mem %" >> $LOG_FILE | |
echo " --------------- [`date +'%F %R'`] --------------- " >> $COL_FILE | |
get_data | |
restart_services | |
fi | |
rm -f $RUN_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment