SlideShare una empresa de Scribd logo
1 de 4
#!/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()
{
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
}
#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
;;
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

Más contenido relacionado

La actualidad más candente

Basicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt applicationBasicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt applicationDinesh Manajipet
 
10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming languageYaroslav Tkachenko
 
我在 Mac 上的常用开发工具
我在 Mac 上的常用开发工具我在 Mac 上的常用开发工具
我在 Mac 上的常用开发工具dennis zhuang
 
Gitosis on Mac OS X Server
Gitosis on Mac OS X ServerGitosis on Mac OS X Server
Gitosis on Mac OS X ServerYasuhiro Asaka
 
Commit2015 kharchenko - python generators - ext
Commit2015   kharchenko - python generators - extCommit2015   kharchenko - python generators - ext
Commit2015 kharchenko - python generators - extMaxym Kharchenko
 
Configuration surgery with Augeas (OggCamp 12)
Configuration surgery with Augeas (OggCamp 12)Configuration surgery with Augeas (OggCamp 12)
Configuration surgery with Augeas (OggCamp 12)Dominic Cleal
 
Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話dcubeio
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたTakeshi Arabiki
 
Building a DSL with GraalVM (VoxxedDays Luxembourg)
Building a DSL with GraalVM (VoxxedDays Luxembourg)Building a DSL with GraalVM (VoxxedDays Luxembourg)
Building a DSL with GraalVM (VoxxedDays Luxembourg)Maarten Mulders
 
Redis as a message queue
Redis as a message queueRedis as a message queue
Redis as a message queueBrandon Lamb
 
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQRealtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQRick Copeland
 
Cis 216 – shell scripting
Cis 216 – shell scriptingCis 216 – shell scripting
Cis 216 – shell scriptingDan Morrill
 
Using the Command Line with Magento
Using the Command Line with MagentoUsing the Command Line with Magento
Using the Command Line with MagentoMatthew Haworth
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationrjsmelo
 

La actualidad más candente (20)

Basicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt applicationBasicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt application
 
Ruby 1.9
Ruby 1.9Ruby 1.9
Ruby 1.9
 
Bash Scripting Workshop
Bash Scripting WorkshopBash Scripting Workshop
Bash Scripting Workshop
 
10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language
 
2015 555 kharchenko_ppt
2015 555 kharchenko_ppt2015 555 kharchenko_ppt
2015 555 kharchenko_ppt
 
我在 Mac 上的常用开发工具
我在 Mac 上的常用开发工具我在 Mac 上的常用开发工具
我在 Mac 上的常用开发工具
 
Gitosis on Mac OS X Server
Gitosis on Mac OS X ServerGitosis on Mac OS X Server
Gitosis on Mac OS X Server
 
Commit2015 kharchenko - python generators - ext
Commit2015   kharchenko - python generators - extCommit2015   kharchenko - python generators - ext
Commit2015 kharchenko - python generators - ext
 
Crack.ba
Crack.baCrack.ba
Crack.ba
 
Configuration surgery with Augeas (OggCamp 12)
Configuration surgery with Augeas (OggCamp 12)Configuration surgery with Augeas (OggCamp 12)
Configuration surgery with Augeas (OggCamp 12)
 
EC2
EC2EC2
EC2
 
Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
 
Building a DSL with GraalVM (VoxxedDays Luxembourg)
Building a DSL with GraalVM (VoxxedDays Luxembourg)Building a DSL with GraalVM (VoxxedDays Luxembourg)
Building a DSL with GraalVM (VoxxedDays Luxembourg)
 
Redis as a message queue
Redis as a message queueRedis as a message queue
Redis as a message queue
 
GoLang & GoatCore
GoLang & GoatCore GoLang & GoatCore
GoLang & GoatCore
 
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQRealtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
 
Cis 216 – shell scripting
Cis 216 – shell scriptingCis 216 – shell scripting
Cis 216 – shell scripting
 
Using the Command Line with Magento
Using the Command Line with MagentoUsing the Command Line with Magento
Using the Command Line with Magento
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
 

Similar a serverstats

Shell Script Disk Usage Report and E-Mail Current Threshold Status
Shell Script  Disk Usage Report and E-Mail Current Threshold StatusShell Script  Disk Usage Report and E-Mail Current Threshold Status
Shell Script Disk Usage Report and E-Mail Current Threshold StatusVCP Muthukrishna
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebookguoqing75
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统yiditushe
 
httpd — Apache Web Server
httpd — Apache Web Serverhttpd — Apache Web Server
httpd — Apache Web Serverwebhostingguy
 
Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7Masahiro Nagano
 
Capital onehadoopclass
Capital onehadoopclassCapital onehadoopclass
Capital onehadoopclassDoug Chang
 
Interface de Voz con Rails
Interface de Voz con RailsInterface de Voz con Rails
Interface de Voz con RailsSvet Ivantchev
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterZendCon
 
Does your configuration code smell?
Does your configuration code smell?Does your configuration code smell?
Does your configuration code smell?Tushar Sharma
 
Артем Маркушев - JavaScript
Артем Маркушев - JavaScriptАртем Маркушев - JavaScript
Артем Маркушев - JavaScriptDataArt
 
Workshop on command line tools - day 2
Workshop on command line tools - day 2Workshop on command line tools - day 2
Workshop on command line tools - day 2Leandro Lima
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoMasahiro Nagano
 
Deploying Plone and Volto, the Hard Way
Deploying Plone and Volto, the Hard WayDeploying Plone and Volto, the Hard Way
Deploying Plone and Volto, the Hard WayAsko Soukka
 
Really useful linux commands
Really useful linux commandsReally useful linux commands
Really useful linux commandsMichael J Geiser
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Shinya Ohyanagi
 
Vagrant file samples for various Hadoop distributions
Vagrant file samples for various Hadoop distributionsVagrant file samples for various Hadoop distributions
Vagrant file samples for various Hadoop distributionsAkshay Gore
 

Similar a serverstats (20)

Shell Script Disk Usage Report and E-Mail Current Threshold Status
Shell Script  Disk Usage Report and E-Mail Current Threshold StatusShell Script  Disk Usage Report and E-Mail Current Threshold Status
Shell Script Disk Usage Report and E-Mail Current Threshold Status
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统
 
httpd — Apache Web Server
httpd — Apache Web Serverhttpd — Apache Web Server
httpd — Apache Web Server
 
Pop3ck sh
Pop3ck shPop3ck sh
Pop3ck sh
 
Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7
 
Capital onehadoopclass
Capital onehadoopclassCapital onehadoopclass
Capital onehadoopclass
 
Command
CommandCommand
Command
 
Interface de Voz con Rails
Interface de Voz con RailsInterface de Voz con Rails
Interface de Voz con Rails
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
 
Does your configuration code smell?
Does your configuration code smell?Does your configuration code smell?
Does your configuration code smell?
 
Артем Маркушев - JavaScript
Артем Маркушев - JavaScriptАртем Маркушев - JavaScript
Артем Маркушев - JavaScript
 
Workshop on command line tools - day 2
Workshop on command line tools - day 2Workshop on command line tools - day 2
Workshop on command line tools - day 2
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
 
PHP PPT FILE
PHP PPT FILEPHP PPT FILE
PHP PPT FILE
 
Puppet Camp 2012
Puppet Camp 2012Puppet Camp 2012
Puppet Camp 2012
 
Deploying Plone and Volto, the Hard Way
Deploying Plone and Volto, the Hard WayDeploying Plone and Volto, the Hard Way
Deploying Plone and Volto, the Hard Way
 
Really useful linux commands
Really useful linux commandsReally useful linux commands
Really useful linux commands
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
Vagrant file samples for various Hadoop distributions
Vagrant file samples for various Hadoop distributionsVagrant file samples for various Hadoop distributions
Vagrant file samples for various Hadoop distributions
 

serverstats

  • 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. { 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. #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. 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