对资源消耗大,浪费严重
GUI不用于负载测试,仅仅用于测试脚本的创建及调试
Linux系统上很难打开一个GUI界面,一般都是命令行使用
jmx 文件运行到非 GUI 模式并生成 HTML 报告Java环境安装配置成功。

Apache JMeter下载安装成功。

GUI模式启动JMeter。

#! /bin/sh:
JAVA_HOME:
MINIMAL_VERSION=8:
JAVA9_OPTS=:
: "${HEAP:="-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m"}":
: "${JMETER_LANGUAGE:="-Duser.language=en -Duser.region=EN"}":
测试计划(Test Plan) -> 添加(Add) -> 线程(Threads) -> 线程组(Thread Group)

线程组(Thread Group) -> 添加(Add) -> 采样器(Sampler) -> HTTP 请求(HTTP Request)


GET请求

服务器名称、路径和参数填写。

测试计划(Test Plan) -> 添加(Add) -> 侦听器(Listener) -> 查看结果树(View Results Tree)

xml、jtl、csv。
注意⚠️:建议使用未存在文件。

保存脚本(.jmx) 并运行。
单击绿色按钮或快捷键{Window}Ctrl+R/{Mac}Command+R运行。

默认配置下,jtl文件保存的字段为:
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
1673149864221,6824,GET API,200,OK,Thread Group 1-1,text,true,,1744,123,1,1,https://reqres.in/api/users?page=2,6823,0,1
| 字段 | 说明 |
|---|---|
| timeStamp | 时间戳,毫秒;如:1673149864221 |
| elapsed | 耗时,毫秒;从发送请求到收到最后一个响应,所花费的时间;不包括渲染请求所花费的时间,同时也不包括处理客户端脚本所花费的时间 |
| label | 取样器名称 如:GET API |
| responseCode | HTTP响应code码;如:200 |
| responseMessage | 响应的message消息;如:OK |
| threadName | 线程名;如:Thread Group 1-1 |
| dataType | 参数的数据类型; |
| success | 请求是否成功; |
| failureMessage | 响应的失败的message消息; |
| bytes | 请求样本字节数 |
| sentBytes | 发送样本字节数 |
| grpThreads | 当前线程组的线程数 |
| allThreads | 所有线程组的线程数 |
| URL | 请求地址路径 |
| Latency | 延迟的耗时 |
| IdleTime | 空闲时间,毫秒; |
| Connect | 连接建立的时间 |
GUI界面从独立的 csv/jtl 文件创建报告。

Results file 浏览选中存储结果的 csv/jtl 文件路径。user.properties 浏览选中{jmeter_path}/bin/jmeter.properties文件。
Output directory 浏览输入HTML报告的文件夹路径。Gererate report,就可以生成 HTML 到Output directory的路径文件夹下。

报错信息:
Generating report
File '/**/api.jtl' does not contain the field names header, ensure the jmeter.save.saveservice.* properties are the same as when the CSV file was created or the file may be read incorrectly when generating report
An error occurred: null
原因: 由于结果文件没有头信息导致。
解决方案: 需要在结果文件jtl/csv中添加上以下对应头信息:
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
报错信息:
Output directory :The directory /**/html isnt empty
原因: 若生成HTML的文件夹已存在,需要为空文件夹,否则生成报告会报错。
解决方案: 选中HTML的文件夹为空文件夹。
静默压测后,命令直接⽣成对应html压测报告。
过程
优点
jmeter -n -t [jmx file] -l [results file] -e -o [Path to web report folder]

jmx file:
JMeter压测脚本文件。jmx file中。results file:
JMeter压测脚本的结果储存文件。JMeter静默压测生成的压测数据,原始的各种压测数据文件。Path to web report folder:
JMeter压测的HTML报告文件。JMeter静默压测的压测数据生成HTML报告文件夹。报错信息:
An error occurred: Cannot write to '/**/html' as folder is not empty
原因: 对应生成报告时报错,代表生成报告的文件夹不是空文件夹。
解决方案: 需要重新指定创建空文件夹。
-n:
nongui;非 GUI 模式,在非 GUI 模式下运行 JMeter 压测脚本。-t:
testfile;指定JMeter脚本,要运行的 JMeter 测试脚本文件。-l:
logfile;JMeter压测结果文件,记录结果样本的文件。-e:
reportatendofloadtests;测试结束后生成报告。-o:
reportoutputfolder;报告的输出文件地址。jmeter -n -t [jmx file] -l [results file]
jmeter -g [results file] -e -o [Path to web report folder]
-g: