注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

网易杭州 QA Team

务实 专注 分享 做有态度的QA

 
 
 
 
 

日志

 
 

awk简单应用,awk外部变量引入  

来自Linsa.Liu   2011-08-12 20:32:41|  分类: 性能测试 |举报 |字号 订阅

  下载LOFTER 我的照片书  |
脚本 computer.sh
#!/bin/bash
#############################################################################
# created by linsa 2011/8/12
#############################################################################
if [ $# -ne 2 ]; then
    echo "usage: computer.sh  <file_dir> <test time(seconds)>"
    echo "eg. sh computer.sh log/ 1800"
    exit
fi

BASE=$1
TIME=$2
echo "computer dir: " $BASE " test time: " $TIME

echo "-----------------statics----------------------------"
  1. grep ResCode $BASE/thumbfiletest.log > $BASE/response
  2. grep -c ResCode $BASE/response |awk '{print "Total Requests: " $1}'
  3. grep ResCode:200 $BASE/response > $BASE/200
  4. awk -F ";" '{print $4}' $BASE/200 > $BASE/200.tmp
  5. awk -F ":" '{print $2}' $BASE/200.tmp > $BASE/200.rt
  6. awk 'BEGIN{a=0;b=0}{a+=$1;b+=1}END{print "Success 200 Requests: " b; print "TPS: " b/"'$TIME'"; print "Success 200 Mean Response Time(ms): " a/b;}' $BASE/200.rt
  7. awk -F ";" '{print $6}' $BASE/200 > $BASE/net.tmp
  8. awk -F ":" '{print $2}' $BASE/net.tmp > $BASE/net
  9. awk 'BEGIN{a=0}{a+=$1}END{print "Recieved Byte/s: " a/"'$TIME'"; print "Recieved kByte/s: " a/1024/"'$TIME'"}' $BASE/net
  10. grep -v ResCode:200 $BASE/response > $BASE/not200
  11. grep -c ResCode: $BASE/not200 |awk '{print "Fail Requests: " $1}'

以上脚本用于性能测试过程中一些基本的数据统计与计算。对awk没什么了解,仅限于简单的使用。
出于学习的目的,拿出来和大家分享,哪位有更好的方式欢迎指教。

awk引入外部变量有两种方式:
1. -v var=$v
2. "'$A'"

输出结果:
ebox@eboxp7v1:~/test/thumbtest$ sh computer.sh log/ 1800
computer dir:  log/   test time:  1800
-----------------statics----------------------------
Total Requests: 5043
Success 200 Requests: 4981
TPS: 2.76722
Success 200 Mean Response Time(ms): 3580.64
Recieved Byte/s: 45032.7
Recieved kByte/s: 43.9772
Fail Requests: 62

以上脚本详解。原始数据为thumbfiletest.log。具体内容为:
[INFO ]16:40:29,482, [Class]ThumbFileQueue, Thread:3; Client mode:web; FileId:3; Request Time:3757; ResCode:200; Received Bytes:6631;
[INFO ]16:40:29,482, [Class]ThumbFileQueue, Thread:6; Client mode:web; FileId:7; Request Time:3758; ResCode:200; Received Bytes:8332;
[INFO ]16:40:29,878, [Class]ThumbFileQueue, Thread:2; Client mode:web; FileId:4; Request Time:4154; ResCode:200; Received Bytes:18382;
[INFO ]16:40:29,878, [Class]ThumbFileQueue, Thread:1; Client mode:web; FileId:2; Request Time:4153; ResCode:200; Received Bytes:18381;
[INFO ]16:40:29,881, [Class]ThumbFileQueue, Thread:4; Client mode:web; FileId:5; Request Time:4156; ResCode:200; Received Bytes:28709;
[INFO ]16:40:31,607, [Class]ThumbFileQueue, Thread:0; Client mode:web; FileId:13; Request Time:2132; ResCode:200; Received Bytes:6153;
[ERROR]16:40:31,607, [Class]ThumbFileQueue, Thread:5; Client mode:web; FileId:15; Request Time:2128; ResCode:1100; Received Bytes:1081;
脚本部分第2条计算所有的请求数,Total Requests
3. 4.5.分离出ResCode:200的数据。6. 基于响应吗为200的数据计算出TPS,平均响应时间
7.8.9计算Received Bytes部分。
  评论这张
 
阅读(498)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016