首页 > 其他 > 详细

Jmeter静默自动化压测脚本

时间:2021-03-11 22:21:40      阅读:36      评论:0      收藏:0      [点我收藏+]
#!/usr/bin/env bash
export jmx_template="test2"
export suffix=".jmx"
export jmx_template_filename="${jmx_template}${suffix}"
export os_type=`uname`

# 需要在系统变量中定义jmeter根目录的位置,如下
#export jmeter_path=/usr/local/jmeter/apache-jmeter-5.2

echo "清空nohup.out"
cat /dev/null > nohup.out

echo "强制杀掉JMeter进程"
killJMeter()
{
    pid=`ps -ef|grep jmeter|grep java|grep ${jmx_filename}|awk {print $2}`
    echo "jmeter Id list :$pid"
    if [[ "$pid" = "" ]]
    then
      echo "no jmeter pid alive"
    else
      kill -9 $pid
    fi
}

echo "自动化压测全部开始"
#压测并发数列表
thread_number_array=(100 200 300)
for num in "${thread_number_array[@]}"
do
    # 生成对应压测线程的jmx文件
    export jmx_filename="${jmx_template}_${num}${suffix}"
    export jtl_filename="test_${num}.jtl"
    export web_report_path_name="web_${num}"

    rm -f ${jmx_filename} ${jtl_filename}
    rm -rf ${web_report_path_name}
    
    cp ${jmx_template_filename} ${jmx_filename}
    echo "生成jmx压测脚本 ${jmx_filename}"

    if [[ "${os_type}" == "Darwin" ]]; then
        sed -i "" "s/thread_num/${num}/g" ${jmx_filename}
    else
        sed -i "s/thread_num/${num}/g" ${jmx_filename}
    fi

    # JMeter 静默压测
    ${jmeter_path}/bin/jmeter -n -t ${jmx_filename} -l ${jtl_filename} 
    
    # 生成web压测报告
    ${jmeter_path}/bin/jmeter -n -t ${jmx_filename} -l ${jtl_filename} 
    
    sleep 30
    killJMeter
done
echo "自动化压测全部结束"

 

Jmeter静默自动化压测脚本

原文:https://www.cnblogs.com/shen-qiang/p/14520284.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!