Resource utilization script for Solaris

18 December, 2006 – 1:14 pm

Recently I found myself in a performance test analyst role on a unix system with no access to customised tools for collecting performance statistics such as Compuware QALoad or Mecury LoadRunner. Not to worry, Solaris 9 comes with a bucket load of native tools that allow you to easily collect statistics. Using a combination of native tools (sar, netstat, top, vmstat and iostat) I wrote a rough but effective shell script to assist in collecting raw performance statistics to later analyse for server resource utilization characterstics.


#~/bin/sh
# #########################################################################
# Server Resource Utilization Monitor
#
# Usage    : ./resource.sh [options]
# Options  :
#     t    duration in seconds to monitor server for
#     n    sample rate every n seconds
#     testID  optional testID used for storing in database
#
# Last edited  : 06 Feb 07 14.00
# Author    : Tim Koopmans
# Version    : 1.1
# #########################################################################
 
duration=$1    #duration in seconds
sampleRate=$2   #sample every n seconds
testID=$3    #optional test ID
service=$4    #business service
 
# LOG FILE NAMES
DTG=`date +%y%m%d%H%M`
logfileSAR=$HOME/logs/$DTG\_$testID\_SAR.log
logfileTOP=$HOME/logs/$DTG\_$testID\_TOP.log
logfileVMSTAT=$HOME/logs/$DTG\_$testID\_VMSTAT.log
logfileIOSTAT=$HOME/logs/$DTG\_$testID\_IOSTAT.log
logfileNETSTAT=$HOME/logs/$DTG\_$testID\_NETSTAT.log
logfileDISK=$HOME/logs/$DTG\_$testID\_DISK.log
 
# SAR
sar $sampleRate $duration | awk '{
  toady="true";
  
  if($6~/2007/)
  {
    YY=substr($6,7,4);
    MM=substr($6,0,2);
    dd=substr($6,4,2);
    dateToday=YY MM dd;
    dateYesterday=dateToday-1;
  }
  
  if($1~/[0-9]*:[0-9]*:[0-9]*/) DTG=$1;
  
  HH=substr(DTG,0,2);
  if(HH>10) {
    HH=HH-11;
    today="true";
  } else {
    HH=24-(11-HH);
    today="false";
  }
  if(HH<10) HH="0"HH;
  mm=substr(DTG,4,2);
  ss=substr(DTG,7,2);
  
  if($2~/^[0-9]+/) {
    if(today=="true"){
      print "\t"dateToday"\t"HH":"mm":"ss"\tSAR    \t"$2"\t"$3"\t"$4"\t"$5"\t'$testID'";  
    } else {
      print "\t"dateYesterday"\t"HH":"mm":"ss"\tSAR    \t"$2"\t"$3"\t"$4"\t"$5"\t'$testID'";  
    }
  }    
  
}' >>$logfileSAR &
 
#IOSTAT
iostat -xnMTd $sampleRate $duration | egrep 'd71|d72|d73|d74|d75|2007' | awk '
{
  if($5~/2007/){
    YY=$5;MM=$2;dd=$3;dateToday=YY"-"MM"-"dd;timeToday=$4;
  }
  else{
    print "\t"dateToday"\t"timeToday"\tDISK\t"$11"\t"$1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9"\t"$10"\t'$testID'";
  }
}' >>$logfileIOSTAT &
 
# VMSTAT
vmstat $sampleRate $duration | awk ' {
print "\t \t \tCPU\t"$1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$12"\t"$18"\t"$19"\t"$20"\t"$21"\t'$testID'";
}' >>$logfileVMSTAT &
 
i="1"
while [ $i -le $duration ]
do
  dateNow=`date -u +%Y%m%d`
  timeNow=`date -u +%H:%M:%S`
    
  # NETSTAT
  printf "\t$dateNow    \t$timeNow    \t">>$logfileNETSTAT
  netstat -k | grep bytes | head -1 |awk '{
    printf "NET\t"$6"\t"$10;
  }' >>$logfileNETSTAT
  printf "\t$testID\n">>$logfileNETSTAT
  
  # DISK SPACE CAPACITY
  printf "\t$dateNow    \t$timeNow    \t">>$logfileDISK
  df -vh | egrep 'd71|d72|d73|d74|d75' | awk '{printf substr($1,13,3)"\t"$5"\t'$testID'\n";}' >>$logfileDISK
 
  #printf "."
  sleep $sampleRate
  i=`expr $i + 1`
done

Share it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netscape
  • Reddit
  • Slashdot
  • Technorati
  • YahooMyWeb

Post a Comment

*
To prove that you're not a bot, enter this code
Anti-Spam Image