Created
March 12, 2013 07:42
-
-
Save ademalp/5140971 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# httpd.load.sh | |
# Script to check the 1-minute server load and sends a mail. | |
# script must be run as root; we run it from crontab every five minutes | |
# Copyright (C) NoBaloney Internet Services | |
# Licensed under GNU General Public License, Version 2 | |
# Required Customizations: | |
SERVER_NAME="SERVER4" | |
EMAIL_ADDRESS="admin@vizyon.net.tr" | |
# Optional Customizations: | |
# path to uptime program | |
UP_TIME=`uptime` | |
# High load warning value (example: 101) means no warning emails | |
# otherwise send warning email if at or above this value | |
LOAD_WARNING="101" | |
# send email and restart httpd if at or above this value | |
HTTPD_RESTART_LOAD="80" | |
# no customizations below this point | |
LOAD_TIME=`date '+%F %H:%M'` | |
TOP_OP=`top -b -n 1 | head -20` | |
TOP[1]=`echo "$UP_TIME"` | |
TOP[2]=`echo "$TOP_OP" | grep 'zombie'` | |
TOP[3]=`echo "$TOP_OP" | grep '%' | grep -v 'PID'` | |
TOP[4]=`echo "$TOP_OP" | grep '^Swap\:'` | |
TOP[5]=`echo "$TOP_OP" | grep '^Mem\:'` | |
ONE_LOAD=`echo "${TOP[1]}" | awk '{print $10}' | cut -c1-4` | |
#echo $ONE_LOAD | |
if [ "$ONE_LOAD" == "aver" ]; then | |
ONE_LOAD=`echo "${TOP[1]}" | awk '{print $11}'| cut -c1-4` | |
fi | |
#echo $ONE_LOAD | |
ONE_LOAD_CALC=`echo "${TOP[1]}" |awk '{print $10}' | cut -c1-4 | awk 'BEGIN {FS = "."}{print $1}'` | |
#echo $ONE_LOAD_CALC | |
if [ "$ONE_LOAD_CALC" == "aver" ]; then | |
ONE_LOAD_CALC=`echo "${TOP[1]}"| awk '{print $11}'| cut -c1-4 | awk 'BEGIN {FS = "."}{print $1}'` | |
fi | |
#echo $ONE_LOAD_CALC | |
ONE_LOAD_SUB="$ONE_LOAD(1min) - $LOAD_TIME" | |
#echo $ONE_LOAD_SUB | |
MAIL_OUTPUT=`echo -e "${TOP[1]}\n${TOP[2]}\n${TOP[3]}\n${TOP[4]}\n${TOP[5]}\n"` | |
#echo -e "\n$MAIL_OUTPUT\n" | |
if [ "$ONE_LOAD_CALC" -ge "$LOAD_WARNING" ]; then | |
echo -e "\nSERVER LOAD of $SERVER_NAME is $ONE_LOAD_SUB\n\n$MAIL_OUTPUT\n" | mail -s "$SERVER_NAME - LOAD WARNING : $ONE_LOAD_SUB" $EMAIL_ADDRESS | |
fi | |
if [ "$ONE_LOAD_CALC" -ge "$HTTPD_RESTART_LOAD" ]; then | |
/etc/init.d/httpd restart 2&> /var/log/cron_load.log && echo -e "\nSERVER LOAD of $SERVER_NAME is $ONE_LOAD_SUB\n" >> /var/log/cron_load.log && echo -e "$MAIL_OUTPUT\n" >> /var/log/cron_load.log && cat /var/log/cron_load.log | mail -s "$SERVER_NAME - HTTPD RESTART : $ONE_LOAD_SUB" $EMAIL_ADDRESS | |
fi | |
#mail -s "Cron: calisti." $EMAIL_ADDRESS | |
exit 0 | |
#END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment