webtest.sh 很不错的WEB服务器压力测试脚本(3)

发表于:2012-04-16来源:linux安全网作者:zhaoyun00点击数: 标签:压力测试
echo 本次测试共下载成功了 $succok 次 file SUCCOK=`echo scale=2;$succok/$sum*100 |bc`% echo \ ; echo \ file echo 本次测试的成功率为 $SUCCOK file fail=`cat fail` echo \ ; echo \ file

  echo "本次测试共下载成功了 $succok 次" >> file

  SUCCOK=`echo "scale=2;$succok/$sum*100" |bc`%

  echo \ ; echo \ >>file

  echo "本次测试的成功率为 $SUCCOK " >> file

  fail=`cat fail`

  echo \ ; echo \ >>file

  echo "本次测试共下载失败了 $fail 次" >>file

  FAIL=`echo "scale=2;$fail/$sum*100" | bc`%

  echo \ ; echo \ >>file

  echo "本次测试的失败率为 $FAIL" >> file

  startfail=`cat startfail |awk '{print $2}'`

  grep fail test.logwhile &> /dev/null

  if [ $? -eq 0 ] ; then

  echo \ ; echo \ >>file

  echo "本次测试在启动第 $startfail 次开始出现下载失败现象。 " >> file

  fi

  fi

  #8$#

  fi

  #7$#

  killall bash &>/dev/null

  ps aux |grep wget |grep -v grep |awk '{print $2}'|xargs kill -9 &>/dev/null

  ps aux |grep test.sh |grep -v grep |awk '{print $2}'|xargs kill -9 &>/dev/null

  sleep 3

  clear

  if [ $MODE = SC -o $MODE = SERVER ] ; then

  for i in {1..1000}

  do

  echo $i > /dev/null

  echo ;

  done

  fi

  clear

  echo ; echo ;

  cat file;rm -f test.logfor;rm -f ok;rm -f whstat;rm -f mem; rm -f cpu; rm -f fail; rm -f succok

  rm -f sum;rm -f startfail;rm -rf established;rm -f test.logwhile;rm -f sta

  echo ; echo ;

  ps aux |grep webtest|grep -v grep |awk '{print $2}'|xargs kill -9 &>/dev/null

  break

  exit

  fi

  #4$#

  echo "Start threads" > ok

  echo "CPU Rate" > cpu

  echo "MEM Rate" > mem

  echo "ESTABLISHED" > established

  I=1000

  #9^#

  if [ $MODE = CLIENT ] ; then

  SPACE=`echo "$SPACE-2"|bc`

  fi

  if [ $BTIME -lt $MAXTIME ] ; then

  I=99999999999999999999999999

  fi

  if [ $NUMBER -lt $MAXNUMBER ] ; then

  I=$MAXNUMBER

  fi

  #9$#

  for ((i=1;i<=$I;i++))

  do

  #10^#

  if [ $MODE = SC -o $MODE = SERVER ] ; then

  ./test.sh &

  fi

  #10$#

  sleep $SPACE

  echo "start $i " >> ok

  STAT=`grep 1 sta &>/dev/null ; echo $?`

  if [ $STAT -eq 1 ] ; then

  grep fail test.logwhile &>/dev/null

  if [ $? -eq 0 ] ; then

  tail -n 1 ok > startfail

  echo 1 > sta

  fi

  fi

  #11^#

  if [ $GRAPH = ON ] ; then

  if [ $MODE = CLIENT -o $MODE = SC ] ; then

  free -m |grep Mem |awk '{print $2,$4+$6+$7}'|awk '{print $1,$1-$2}'| awk '{print $2/$1*100}'>>mem

  top -n 2 |grep Cpu |tail -n 1 |awk -F, '{print $1}' |awk -F: '{print $2}' |awk -F% '{print $1}'|awk -F" " '{print $2}' >>cpu

  netstat -antlp |egrep '[443|ESTAB|$SERVER]' | wc -l >>established

  fi

  fi

  #11$#

  #12^#

  if [ $BTIME = $MAXTIME -o $BTIME -gt $MAXTIME ] ; then

  if [ $NUMBER = $MAXNUMBER -o $NUMBER -gt $MAXNUMBER ] ; then

  grep fail test.logwhile &>/dev/null

  #13^#

  if [ $? -eq 0 ] ; then

  echo 1 > whstat

  break

  fi

  #13$#

  fi

  #12--#

  else

  #14^#

  if [ $BTIME -lt $MAXTIME ] ; then

  T=`cat time`

  C=`echo "$TIME+$T" |bc`

  N=`date +%s`

  V=`echo "$N-$C"|bc`

  #15^#

  if [ $V -gt $BTIME ] ; then

  grep fail test.logwhile | wc -l |awk '{print $1}' >fail

  grep ok test.logwhile |wc -l |awk '{print $1}' >succok

  wc -l test.logwhile |awk '{print $1}' > sum

  echo 1 > whstat

  break

  fi

  #15$#

  fi

  #14$#

  fi

  #12$#

  #18^#

  if [ $NUMBER -eq $MAXNUMBER -o $NUMBER -gt $MAXNUMBER ] ; then

  #13^#

  # if [ ! $BTIME = $MAXTIME -o $BTIME -gt $MAXTIME ] ;then

  grep fail test.logwhile &>/dev/null

原文转自:http://www.ltesting.net