Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
#!/bin/bash
# serverstats.sh Written by Ben De Koster
# Last modified on 09/05/13
##Variables
HTTPD='/usr/local/apache/con...
{
echo -e "$Greenn=== Exim Stats ===$NoColorn"
echo -e "Exim procs: `ps faux | grep exim -c`"
echo "Emails in queue: `exim...
#Apache ops
apacheops()
{
echo -e "$Greenn=== Apache Configuation ===$NoColorn"
echo "Apache version: `httpd -v | grep "Se...
apache)
basic
apacheproc
apacheops
;;
exim)
basic
eximwqueue
;;
mysql)
basic
mysqlproc
mysqlops
;;
syn)
basic
syn
;;
ops)
...
Upcoming SlideShare
Loading in …5
×

serverstats

114 views

Published on

  • Be the first to comment

  • Be the first to like this

serverstats

  1. 1. #!/bin/bash # serverstats.sh Written by Ben De Koster # Last modified on 09/05/13 ##Variables HTTPD='/usr/local/apache/conf/httpd.conf' PHP=`php -i | grep php.ini | grep "Configuration" | cut -d ">" -f2 | cut -c 2- | tail -n 1`; PHPVER=`php -i | grep "PHP Version" | awk '{print $4}' | head -n 1`; MYSQL='/etc/my.cnf' IOSTAT=( $(iostat 1 2 | grep iowait -A1 | awk '{print $4}' | grep -v system) ) #Colors Red='e[0;31m' Green='e[0;32m' Blue='e[0;34m' NoColor='e[0m' ##Meat of script #Basic server stats basic() { echo -e "$Greenn=== SERVER STATS ===$NoColorn" echo -e "Host: `hostname`" } #Disk Space disk() { echo -e "$Greenn=== Disk Space Usage ===$NoColorn" df -h } #Currently running mysql queries mysqlproc() { echo -e "$Greenn=== MySQL Database queries ===$NoColorn" mysqladmin proc stat } #Number of messages in the queue and currently running exim procs eximnoqueue() { echo -e "$Greenn=== Exim Stats ===$NoColorn" echo -e "Exim procs: `ps faux | grep exim -c`" } eximwqueue()
  2. 2. { echo -e "$Greenn=== Exim Stats ===$NoColorn" echo -e "Exim procs: `ps faux | grep exim -c`" echo "Emails in queue: `exim -bpc`" } #For checking for SYN floods. syn() { echo -e "$Greenn=== Number of SYN connections ===$NoColorn" netstat -nap | grep SYN | wc -l echo -e "$Greenn=== Top 10 SYN Flood Conections ===$NoColorn" netstat -tn 2>/dev/null | grep SYN | awk '{print $5}' | cut -f1 -d: | sort | uniq -c | sort -rn | head } #PHP ops php() { echo -e "$Greenn=== PHP Info ===$NoColorn" #echo "PHP version: `php -v | head -n 1 | awk '{print $2}'`" #echo "PHP version: `php -i | grep "PHP Version" | awk '{print $4}'`" echo "PHP version: $PHPVER" echo "PHP handler: `/usr/local/cpanel/bin/rebuild_phpconf --current | grep "PHP5 SAPI:" | awk '{print $3}'`" egrep 'max_execution_time|max_input_time|memory_limit' $PHP | awk '{print $1,$2,$3}' } #Apache statistics apacheproc() { echo -e "$Greenn=== Number of HTTPD Processes ===$NoColorn" ps faux | grep httpd -c | grep -v grep echo -e "$Greenn=== Top 10 connections to port 80 ===$NoColorn" netstat -tn 2>/dev/null | awk '{if ($4 ~ ":80") print $5}'| sed -e 's/::ffff://' | cut -d: - f1 | sort | uniq -c | sort -rn|head } #Current memory usage mem() { echo -e "$Greenn=== Current Memory Usage ===$NoColorn" free -m }
  3. 3. #Apache ops apacheops() { echo -e "$Greenn=== Apache Configuation ===$NoColorn" echo "Apache version: `httpd -v | grep "Server version" | awk '{print $3}'| cut -d '/' - f2`" echo "Server MPM: `httpd -V | grep MPM_DIR | cut -d '/' -f3 | cut -d '"' -f1`" egrep 'MaxClients|KeepAlive|MaxRequestsPerChild|Timeout|Servers|Threads|ServerLimit ' $HTTPD | egrep -v 'SSL|#' } #MySQL ops and highest historic number of connections since MySQL was last started mysqlops() { echo -e "$Greenn=== MySQL Configuration ===$NoColorn" echo "MySQL Version: `mysql -V | awk '{print $5}' | cut -d',' -f1`" mysqladmin extended-status | grep Max_used_connections | awk '{print $2,$4}' sed -n '/[mysqld]/,/[/p' $MYSQL|grep -v "["|grep "[a-zA-Z0-9]" } #Miscellaneous Stats misc() { echo -e "$Greenn=== Miscellaneous Stats ===$NoColorn" echo "I/O Wait: `echo ${IOSTAT[1]}`" echo "CPUs: `grep proc -c /proc/cpuinfo`" echo "Cpanel Extra CPUs: `grep extracpus /var/cpanel/cpanel.config | cut -d = -f2`" } #To specify what stats you want to run case "$1" in all) basic disk mysqlproc eximnoqueue syn php apacheproc mem apacheops mysqlops misc ;;
  4. 4. apache) basic apacheproc apacheops ;; exim) basic eximwqueue ;; mysql) basic mysqlproc mysqlops ;; syn) basic syn ;; ops) php apacheops mysqlops ;; misc) basic disk mem misc ;; *) echo -e "$RednOops! Looks like an invalid argument was used. Avaliable options are:" echo -e "$Greennall - display all stats" echo "apache - display apache stats and config" echo "mysql - display mysql stats and config" echo "exim - number of exim procs and messages in queue" echo "syn - number of SYN connections and top 10 IP's making the most SYN connections" echo "ops - display php, apache, and mysql ops" echo -e "misc - miscellaneious stats $NoColor" esac exit 0

×