• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

收集Linux系统资源,导入到LoadRunner测试结果

发布: 2009-4-22 22:06 | 作者: 网络转载 | 来源: 测试时代采编 | 查看: 156次 | 进入软件测试论坛讨论

领测软件测试网 LoadRunner的结果分析器自带数据导入功能,以下脚本即可办到:
    收集数据 == $ performanceMonitor.sh run    保存到CSV文件 == $ performanceMonitor.sh csv YYYYMMDD
脚本代码:
LOG=/home/higkoo/PerfMon/
SLEEP=10
HDD=2

HTYPE=$(uname -s)

genStat()
{
    now=$( date +%S )
    while [ "$now" -ne "30" ]
    do
        sleep 1
        now=$( date +%S )
    done
    while :;
    do
        dat=$(date +%Y%m%d,%H:%M:%S)
        day=$(date +%Y%m%d )
        iostat -x 1 2 | sed -e"s/^\(.*\)/$dat \1/" | grep "[0-9]\." | tail -${HDD} >> ${LOG}/io.${day}.log &
        vmstat 1 2 | awk "{ print \"$dat\", \$0 }" | tail -1 >> ${LOG}/vm.${day}.log &
        netstat -i | grep -v Iface | awk "{ print \"$dat\", \$0 }" >> ${LOG}/netstat.${day}.log &
        uptime >> ${LOG}/uptime.${day}.log &
        sleep $SLEEP
    done
}

mkcsv()
{
    dat=$1

    if [ "$HTYPE" == "SunOS" ]
    then
   
        #IO CSV
        echo date,time,device,r/s,w/s,kr/s,kw/s,wait,actv,wsvc_t,asvc_t,%w,%b > ${LOG}/io.${dat}.csv
        cat ${LOG}/io.${dat}.log | egrep -v "extended|device" | awk '{ OFS=","; print $1,$12,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11 }' >> ${LOG}/io.${dat}.csv
        #VM csv
        echo date,time,k[r],k[b],k[w],swap,free,pg[re],pg[mf],pg[pi],pg[po],pg[fr],pg[de],pg[sr],m0,m1,m2,m1,interupt,syscall,ctxswt,cpu[us],cpu[sys],cpu[idl] > ${LOG}/vm.${dat}.csv
        cat ${LOG}/vm.${dat}.log | awk '{for(l=1;l<23;l++) { printf("%s,", $l) }; print $23 }' >> ${LOG}/vm.${dat}.csv
        #uptime csv
        echo time,users,5min,10min,15min > ${LOG}/uptime.${dat}.csv
        cat ${LOG}/uptime.${dat}.log | awk '{ OFS=","; if ( $6 ~ /^[hm][ri]/) { print $1,$7,$11$12$13 } else if ( $6 ~/^user/) { print $1,$5,$9$10$11} else { print $1,$6,$10$11$12} }' >> ${LOG}/uptime.${dat}.csv

    elif [ "$HTYPE" == "Linux" ]
    then
        #IO CSV
        echo "date,time,device,rrqm/s,wrqm/s,r/s,w/s,rsec/s,wsec/s,rkB/s,wkB/s,avgrq-sz,avgqu-sz,await,svctm,%util" > ${LOG}/io.${dat}.csv
        cat ${LOG}/io.${dat}.log | egrep -v "extended|device" | awk '{for(l=1;l<15;l++) { printf("%s,", $l) }; print $15}' >> ${LOG}/io.${dat}.csv
        #VM csv
        echo date,time,r,b,swp,free,buff,cache,si,so,bi,bo,in,cs,us,sy,id,wa > ${LOG}/vm.${dat}.csv
        cat ${LOG}/vm.${dat}.log | awk '{for(l=1;l<17;l++) { printf("%s,", $l) }; print $17 }' >> ${LOG}/vm.${dat}.csv
        #uptime csv
        echo time,users,5min,10min,15min > ${LOG}/uptime.${dat}.csv
        cat ${LOG}/uptime.${dat}.log | awk '{ OFS=","; if ( $4 ~ /^min/) { print $1,$5,$9$10$11 } else { print $1,$4,$8$9$10} }' >> ${LOG}/uptime.${dat}.csv
    else

        echo "Hmmm - An unexpected error occured. Have you change the host type?"
   
    fi

}

if [ "$HTYPE" != "SunOS" -a "$HTYPE" != "Linux" ]
then
    echo "Error - This script has no knowlege of the System $HTYPE"
    echo "        You will need to do some tweaking."
    exit
fi

case $1 in

    run)
        genStat
        ;;
    csv)
        if [ $# -lt 2 ]
        then
            echo "Error - You must supply a date in the form YYYYMMDD"
            exit
        fi
        mkcsv $2
        ;;
    *)
        echo -e ":::: Usage ::::"
        echo -e "$0 run             : Collect stats"
        echo -e "$0 csv YYYYMMDD    : Generate CSV from stats"
        echo ""
        ;;
esac脚本可能需要根据实际情况稍作修改,然后将保存的数据导入到LoadRunner里就可以合成到测试结果中了:

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/

TAG: linux Linux LINUX loadrunner LoadRunner Loadrunner loadRunner 结果 系统 资源


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网