jmeter no-JUI执行常用命令(四)

 一、常用命令简述 

-n, --nongui
命令行界面启动jmeter
-t, --testfile {filename}
jmx结尾的测试计划,支持相对路径
-l, --logfile {filename}
日志结果文件
-e,--reportatendofloadtests
负载测试后生成报告仪表板
-o,--reportoutputfolder <参数>
报告仪表板的输出文件夹

1.本机执行
jmeter -n -t biadu.jmx -l ./jtl/result.jtl -e -o ./reports

注意:result.jtl不存在    reports需是空文件夹

2. -r,-runremote

#启动远程服务器(在remote_hosts中定义)
jmeter -n -r -t 线程组.jmx -l ./jtl/result.jtl -e -o ./reports

3.-R,--remotestart <参数>

#启动这些远程服务器(覆盖remote_hosts)
jmeter -n -R 192.168.xx.xx:1099 -t 线程组.jmx -l ./jtl/result.jtl -e -o ./reports

4.#仅执行生成jtl结果

jmeter -n  -t 线程组.jmx -l ./jtl/result.jtl

5.#根据jtl文件生成html报告

jmeter -g ./jtl/result.jtl -o ./reports

二、使用-J -D在运行前动态设置属性,可以用来控制测试计划的执行,在非GUI方式运行时还是比较方便

1. JMeter提供了方法可以动态修改属性,在命令行使用 -J 来指定JMeter Properties

使用__P() 函数来获取命令中指定的属性值。

实例如下:

 执行指令:jmeter -JthreadNum=1 -Jtime=1 -Jcycle=5 -n -t baidu.jmx

threadNum=1为log.jmx测试计划要指定的线程数

-Jtime=1为log.jmx测试计划要指定的持续运行时间

-Jcycle=5为log.jmx测试计划要指定的每个线程的迭代次数

 2.JMeter 命令行通过-D来指定System Properties,类似于Jdk中我们用-D来指定一些系统属性,比如开启JMX远程监控。

   如果访问的目标地址变化了,端口也变化了,重新指定:

  在JMeter脚本中我们用__property()函数来获取,比如-Durl=www.baidu.com在测试计划中用${__property(url,,)}来获取

 执行指令:

       jmeter -Durl=www.baidu.com -JthreadNum=1 -Jtime=1 -Jcycle=5 -n -t baidu.jmx

Jmeter命令参数拓展参考(Google翻译):

用法
-?
打印命令行选项并退出
-h,--help
打印使用情况信息并退出
-v,--version
打印版本信息并退出
-p,--propfile <参数>
要使用的jmeter属性文件
-q,--addprop <参数>
其他JMeter属性文件
-t,--testfile <参数>
要运行的jmeter test(.jmx)文件。 “ -t LAST”将最后加载
使用文件
-l,-logfile <参数>
将样本记录到的文件
-i,--jmeterlogconf <参数>
jmeter日志记录配置文件(log4j2.xml)
-j,--jmeterlogfile <参数>
jmeter运行日志文件(jmeter.log)
-n,--nongui
在nongui模式下运行JMeter
-s,--server
运行JMeter服务器
-E,--proxyScheme <参数>
设置用于代理服务器的代理方案
-H,--proxyHost <参数>
设置供JMeter使用的代理服务器
-P,-proxyPort <参数>
设置代理服务器端口以供JMeter使用
-N,--nonProxyHosts <参数>
设置非代理主机列表(例如* .apache.org | localhost)
-u,--username <参数>
设置JMeter要使用的代理服务器的用户名
-a,--password <参数>
设置JMeter使用的代理服务器的密码
-J,--jmeterproperty <参数> = <值>
定义其他JMeter属性
-G,--globalproperty <参数> = <值>
定义全局属性(发送到服务器)
例如-Gport = 123
或-Gglobal.properties
-D,--systemproperty <参数> = <值>
定义其他系统属性
-S,--systemPropertyFile <参数>
其他系统属性文件
-f,-forceDeleteResultFile
强制删除现有结果文件和Web报告文件夹,如果
在开始测试之前
-L,--loglevel <参数> = <值>
[category =]级别,例如jorphan = INFO,jmeter.util = DEBUG或com
.example.foo =警告
-r,-runremote
启动远程服务器(在remote_hosts中定义)
-R,--remotestart <参数>
启动这些远程服务器(覆盖remote_hosts)
-d,--homedir <参数>
要使用的jmeter主目录
-X,--remoteexit
测试结束时退出远程服务器(非GUI)
-g,--reportonly <参数>
仅从测试结果文件生成报告仪表板
-e,--reportatendofloadtests
负载测试后生成报告仪表板
-o,--reportoutputfolder <参数>
报告仪表板的输出文件夹

亲测后总结,参考原文链接:https://www.cnblogs.com/liu-ke/p/7929233.html

原文地址:https://www.cnblogs.com/xiaozhaoboke/p/13846452.html