Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates Completed, Please Merge #2

Merged
merged 15 commits into from Mar 5, 2014
40 changes: 35 additions & 5 deletions bin/loadwatch_cpanel.sh
Expand Up @@ -2,6 +2,11 @@
# Created by: Liquid Web
# Enhanced by: Phill Coxon, Will Ashworth

# get binaries and their paths
PHP=`which php`
PERL=`which perl`
MYSQL=`which mysql`

# Config
FILE=loadwatch.`date +%F.%H.%M.%S`

Expand All @@ -12,14 +17,16 @@ SUBJECT="Loadwatch notification for $HOSTNAME at ".`date +%F.%H.%M`
EMAILMESSAGE="/tmp/emailmessage.txt"

# Delete when "X" days old
REMOVE="5"
REMOVE="30"

# Notification Email Address
EMAIL="root@localhost"

# Load Threshold for doing a dump (4 is a good number to start with)
THRESH=4

# Option to include MySQL Tuner results
MYSQL_TUNER="$DIR/bin/thirdparty/mysqltuner.pl"


######################################################################################################
Expand All @@ -32,7 +39,7 @@ FORCE=0
# Useful functions to help with organization
function usage
{
echo "usage: loadwatch.sh [-d | --dir] [-e | --email] [-f | --file] [-r | --remove] [-t | --threshold] [-x | --force] [-h | --help]"
echo "usage: loadwatch.sh [-d | --dir] [-e | --email] [-f | --file] [-r | --remove] [-t | --threshold] [-x | --force] [--init] [-h | --help]"
}

# get parameters so we can tailor use of the script on the fly without editing
Expand All @@ -53,6 +60,8 @@ while [ "$1" != "" ]; do
-t | --threshold ) shift
THRESH=$1
;;
--init ) INIT=1
;;
-x | --force ) FORCE=1
;;
-h | --help ) usage
Expand All @@ -64,6 +73,23 @@ while [ "$1" != "" ]; do
shift
done

# If INIT is triggered, we'll handle the basic setup for you
if [[ $INIT = 1 ]];
then

echo "Setting things up...";

echo "Going into loadwatch directory..."; cd $DIR/bin;
echo "Copying cPanel script to safe, usable, file..."; cp $DIR/bin/loadwatch_cpanel.sh $DIR/bin/loadwatch.sh;
echo "Setting permissions on Loadwatch script..."; chmod u+x $DIR/bin/loadwatch.sh;
echo "Setting permissions on MySQL Tuner script..."; chmod u+x $DIR/bin/thirdparty/mysqltuner.pl;
echo "Going back to the loadwatch directory..."; cd $DIR;

echo "Okay. All done! :)";

exit
fi

# Pull load average, log
LOAD=`cat /proc/loadavg | awk '{print $1}' | awk -F '.' '{print $1}'`

Expand Down Expand Up @@ -112,7 +138,7 @@ then
echo " " >> $DIR/$FILE

# Current Disk Usage
echo -e "######## Current Disk Usage (df -h): ########\n" >> $DIR/$FILE
echo -e "\n######## Current Disk Usage (df -h): ########\n" >> $DIR/$FILE
df -h >> $DIR/$FILE
echo " " >> $DIR/$FILE

Expand Down Expand Up @@ -162,6 +188,10 @@ then
mysqladmin stat >> $DIR/$FILE
mysqladmin proc >> $DIR/$FILE

# MySQL Tuner
echo -e "\n\nMySQL Tuner Output:------------------------------------------------------------" >> $DIR/$FILE
$PERL $MYSQL_TUNER >> $DIR/$FILE

# Apache
echo -e "\n\nApache Full Status------------------------------------------------\n\n" >> $DIR/$FILE
/sbin/service httpd fullstatus >> $DIR/$FILE
Expand All @@ -183,9 +213,9 @@ then
ps auxf >> $DIR/$FILE

# Email the notification + summary
/bin/mail -s "$SUBJECT" "$EMAIL" < $DIR/$FILE
/bin/mail -s "$SUBJECT" "$EMAIL" < $DIR/$FILE

fi

# Clean up to remove files older than x days
find $DIR/loadwatch.* -mtime +$REMOVE -exec rm {} \;
find $DIR/loadwatch.* -mtime +$REMOVE -exec rm {} \;