Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Incorporate Will's Awesome Stuff #1

Merged
merged 11 commits into from

2 participants

@getresults
Owner

No description provided.

Will Ashworth added some commits
Will Ashworth Minor Improvements
- rename load watch script for cPanel to match README
4966260
Will Ashworth Clean Up + Basic Enhancements
- added disk usage
- general comment clean-up
- organization of file
6ed29a5
Will Ashworth Auto-Delete logic
- added initial auto delete logic
- allows user to specify age before delete occurs
- does not touch the `checklog` file in any way
- removes `load watch.***` files older than specified age
a7aede9
@ashworthconsulting

Commented out the trip statement for now, allowing for testing to happen without high load on an actual server.

Additional notes that didn't make it into the comments:

  • Also added seconds to the filename when created.
  • Auto-deletion has been tested and confirmed functioning.

If you'd like to test, just run the following command(s):

# trigger the script a few times so you have some files to actually delete
# sh /root/loadwatch/bin/loadwatch_cpanel.sh

# change the timestamp of the files you created to 2012
# touch -a -m -t 201201181205.09 /root/loadwatch/loadwatch.*

# run the script again, at which point your "old" files should be gone
# sh /root/loadwatch/bin/loadwatch_cpanel.sh
Will Ashworth added some commits
Will Ashworth Major Changes
- restructured logic in large part
- added conditions to support parameters
- added `-x` or `--force` options added to allow you to force it to run (regardless of the current load threshold)
- added `-d` or `--dir` options added to allow you to override the $DIR variable
- added `-e` or `--email` options added to allow you to override the $EMAIL variable
- added `-f` or `--file` options added to allow you to override the $FILE variable
- added `-r` or `--remove` options added to allow you to override the $REMOVE variable, changing your `remove after x days` logic on the fly
- added `-t` or `--threshold` options added to allow you to override the $THRESH variable
- added `-h` or `--help` options, allowing help and usage information to display to the user
- various other clean-up
d3857f0
Will Ashworth Bug Fix
- fixed high level if() statement syntax (it was off a bit)
72adade
Will Ashworth Bug Fix
Still attempting to get this error to leave...

root@hostname [~/loadwatch]# sh bin/loadwatch_cpanel.sh
bin/loadwatch_cpanel.sh: line 68: [: missing `]'
bin/loadwatch_cpanel.sh: line 68: [: =: unary operator expected
abf509d
Will Ashworth Bug fix
- Another attempt
643e422
Will Ashworth Bug fix 562bfef
Will Ashworth Bug Fix
- fixed if() statement finally (I think)
a4e7595
Will Ashworth Bug fix
- fixed if() statement. it's tested and working now.
6dabaf1
Will Ashworth Bug fix aba5d46
@getresults getresults merged commit 14b9d99 into getresults:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 4, 2014
  1. Minor Improvements

    Will Ashworth authored
    - rename load watch script for cPanel to match README
Commits on Mar 5, 2014
  1. Clean Up + Basic Enhancements

    Will Ashworth authored
    - added disk usage
    - general comment clean-up
    - organization of file
  2. Auto-Delete logic

    Will Ashworth authored
    - added initial auto delete logic
    - allows user to specify age before delete occurs
    - does not touch the `checklog` file in any way
    - removes `load watch.***` files older than specified age
  3. Major Changes

    Will Ashworth authored
    - restructured logic in large part
    - added conditions to support parameters
    - added `-x` or `--force` options added to allow you to force it to run (regardless of the current load threshold)
    - added `-d` or `--dir` options added to allow you to override the $DIR variable
    - added `-e` or `--email` options added to allow you to override the $EMAIL variable
    - added `-f` or `--file` options added to allow you to override the $FILE variable
    - added `-r` or `--remove` options added to allow you to override the $REMOVE variable, changing your `remove after x days` logic on the fly
    - added `-t` or `--threshold` options added to allow you to override the $THRESH variable
    - added `-h` or `--help` options, allowing help and usage information to display to the user
    - various other clean-up
  4. Bug Fix

    Will Ashworth authored
    - fixed high level if() statement syntax (it was off a bit)
  5. Bug Fix

    Will Ashworth authored
    Still attempting to get this error to leave...
    
    root@hostname [~/loadwatch]# sh bin/loadwatch_cpanel.sh
    bin/loadwatch_cpanel.sh: line 68: [: missing `]'
    bin/loadwatch_cpanel.sh: line 68: [: =: unary operator expected
  6. Bug fix

    Will Ashworth authored
    - Another attempt
  7. Bug fix

    Will Ashworth authored
  8. Bug Fix

    Will Ashworth authored
    - fixed if() statement finally (I think)
  9. Bug fix

    Will Ashworth authored
    - fixed if() statement. it's tested and working now.
  10. Bug fix

    Will Ashworth authored
This page is out of date. Refresh to see the latest.
Showing with 80 additions and 28 deletions.
  1. +80 −28 bin/{loadwatch.cpanel.sh → loadwatch_cpanel.sh}
View
108 bin/loadwatch.cpanel.sh → bin/loadwatch_cpanel.sh
@@ -1,29 +1,76 @@
#!/bin/bash
-# let's add a version num for easier identification:
-# PAC version 0.2
-# NOTE: Need to monitor logfiles as they will keep growing and need to be deleted
+# Created by: Liquid Web
+# Enhanced by: Phill Coxon, Will Ashworth
-#config
-FILE=loadwatch.`date +%F.%H.%M`
-#loadwatch log directory
+# Config
+FILE=loadwatch.`date +%F.%H.%M.%S`
+
+# Loadwatch log directory
DIR=/root/loadwatch
COLUMNS=512
SUBJECT="Loadwatch notification for $HOSTNAME at ".`date +%F.%H.%M`
EMAILMESSAGE="/tmp/emailmessage.txt"
-# notification Email Address
+# Delete when "X" days old
+REMOVE="5"
+# Notification Email Address
EMAIL="root@localhost"
-#Load Threshold for doing a dump.
+# Load Threshold for doing a dump (4 is a good number to start with)
THRESH=4
-#pull load average, log
+
+
+######################################################################################################
+################################# PLEASE DO NOT EDIT BELOW THIS LINE #################################
+######################################################################################################
+
+# Other Variables
+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]"
+}
+
+# get parameters so we can tailor use of the script on the fly without editing
+while [ "$1" != "" ]; do
+ case $1 in
+ -d | --dir ) shift
+ DIR=$1
+ ;;
+ -e | --email ) shift
+ EMAIL=$1
+ ;;
+ -f | --file ) shift
+ FILE=$1
+ ;;
+ -r | --remove ) shift
+ REMOVE=$1
+ ;;
+ -t | --threshold ) shift
+ THRESH=$1
+ ;;
+ -x | --force ) FORCE=1
+ ;;
+ -h | --help ) usage
+ exit
+ ;;
+ * ) usage
+ exit 1
+ esac
+ shift
+done
+
+# Pull load average, log
LOAD=`cat /proc/loadavg | awk '{print $1}' | awk -F '.' '{print $1}'`
-#trip
-if [ $LOAD -ge $THRESH ]
+# Trip (check whether or not to run it)
+if [[ $LOAD -eq $THRESH ]] || [[ $FORCE = 1 ]];
then
+
# Only log triggered loads.
echo `date +%F.%X` - Load: $LOAD >> $DIR/checklog
echo -e "Loadwatch Threshhold: $THRESH, Current Load: $LOAD" >> $DIR/$FILE
@@ -31,10 +78,9 @@ then
#log
echo -e "Loadwatch tripped, dumping info to $DIR/$FILE \n" >> $DIR/checklog
echo -e "\nCurrent server time: " . `date +"%c"` >> $DIR/$FILE
- #echo "LoadWatch on $HOSTNAME triggered. Please Check it out." > $EMAILMESSAGE
+ echo "LoadWatch on $HOSTNAME triggered. Please Check it out." > $EMAILMESSAGE
#email (optional, set email address to customer and uncomment below lines)
-
#/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
#summary
@@ -59,18 +105,28 @@ then
echo "MYSQL CPU consumption: $MYSQLCPU %" >> $DIR/$FILE
MYSQLMEM=`top -n 1 -S -b -U mysql|tail -n 2|head -n 1|awk {'print $6'}`
echo "MYSQL RAM consumption: $MYSQLMEM" >> $DIR/$FILE
-
+
+ # Uptime
echo -e "\n######## Uptime: ########\n" >> $DIR/$FILE
uptime >> $DIR/$FILE
+ echo " " >> $DIR/$FILE
+
+ # Current Disk Usage
+ echo -e "######## Current Disk Usage (df -h): ########\n" >> $DIR/$FILE
+ df -h >> $DIR/$FILE
+ echo " " >> $DIR/$FILE
+ # Free Memory (Mb)
echo -e "\n######## Free Memory (Mb): ########\n" >> $DIR/$FILE
free -m >> $DIR/$FILE
echo " " >> $DIR/$FILE
+ # CPU top 20
echo -e '\n######## CPU top 20 ########\n' >> $DIR/$FILE
top -bcn1 | head -n 26 >> $DIR/$FILE
echo " " >> $DIR/$FILE
+ # Memory top 20
echo -e '\n######## Mem top 20 ########\n' >> $DIR/$FILE
top -bmcn1 | head -n 26 >> $DIR/$FILE
echo " " >> $DIR/$FILE
@@ -79,61 +135,57 @@ then
# Historical CPU Usage
-
echo -e "######## Historical CPU Usage (sar -p): ########\n" >> $DIR/$FILE
sar -p >> $DIR/$FILE
echo " " >> $DIR/$FILE
# Historical Memory Usage
# Note - should be -S on newer versions of sar. At the moment WHM/cPanel seems to be running sar V9.0.4
-
echo -e "######## Historical Memory Usage (sar -r): ########\n" >> $DIR/$FILE
sar -r >> $DIR/$FILE
echo " " >> $DIR/$FILE
# Historical Disk IO
-
echo -e "######## Historical Disk I/O Usage (sar -d): ########\n" >> $DIR/$FILE
sar -d >> $DIR/$FILE
echo " " >> $DIR/$FILE
-
+ # Sites with traffic in the last 60 seconds
echo -e "######## Sites with traffic in the last 60 seconds: ########\n" >> $DIR/$FILE
find /usr/local/apache/domlogs/ -maxdepth 1 -type f -mmin -1 | egrep -v 'offset|_log$' >> $DIR/$FILE
-
# -- End: WHM/cPanel Only by default (requires sar) ---
-
- #mysql
+ # MySQL
echo -e "\n\nMySQL:------------------------------------------------------------\n\n" >> $DIR/$FILE
mysqladmin stat >> $DIR/$FILE
mysqladmin proc >> $DIR/$FILE
- #apache
+ # Apache
echo -e "\n\nApache Full Status------------------------------------------------\n\n" >> $DIR/$FILE
/sbin/service httpd fullstatus >> $DIR/$FILE
- #network
+ # Network
echo -e "\n\nNetwork------------------------------------------------------------\n\n" >> $DIR/$FILE
netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head >> $DIR/$FILE
echo -e "\n\nNetwork 2----------------------------------------------------------\n\n" >> $DIR/$FILE
netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f4 | sort | uniq -c | sort -nr | head >> $DIR/$FILE
- #email
+ # Email
echo -e "\n\nEmail------------------------------------------------------------\n\n" >> $DIR/$FILE
#EXIMQUEUE=`exim -bpc`
#echo "Exim Queue: $EXIMQUEUE " >> $DIR/$FILE
/usr/sbin/exiwhat >> $DIR/$FILE
- #process list
+ # Process List
echo -e "\n\nProcesses------------------------------------------------------------\n\n" >> $DIR/$FILE
ps auxf >> $DIR/$FILE
- #Email the notification + summary
-
+ # Email the notification + summary
/bin/mail -s "$SUBJECT" "$EMAIL" < $DIR/$FILE
-
fi
+
+# Clean up to remove files older than x days
+find $DIR/loadwatch.* -mtime +$REMOVE -exec rm {} \;
Something went wrong with that request. Please try again.