code学习

linux 下 自动化跑压测脚本

笔者在linux下执行 jmeter 压测脚本时,需要手工输入 jmeter -n -t xxx.jmx -l xxx.jtl 挺麻烦的,还需要去修改线程数,加压时长等繁琐操作,为了一劳永逸,考虑shell脚本自动化实现。

1、vi XXX.jmx 文件,分别修改三个值:ThreadGroup.num_threads,ThreadGroup.ramp_time,ThreadGroup.duration为:

${__P(threadNum)},${__P(threadSec)},${__P(durationSec)}

       <stringProp name="ThreadGroup.num_threads">${__P(threadNum)}</stringProp>

       <stringProp name="ThreadGroup.ramp_time">${__P(threadSec)}</stringProp>

       <boolProp name="ThreadGroup.scheduler">true</boolProp>

       <stringProp name="ThreadGroup.duration">${__P(durationSec)}</stringProp>

       <stringProp name="ThreadGroup.delay"></stringProp>

2、自动化脚本

echo -n "Please input thread num(10):"

read cmd1

echo -n "Please input  Number of threads executed in seconds(1):"

read cmd2

echo -n "Please input the Pressurizing time (seconds)(30):"

read cmd3