1.简介
MeterPluginCMD命令行工具生成png图片和csv统计文件 Jmeter是个纯java的开源的轻量级性能测试工具,功能强大。因为是轻量级的,与loadrunner相比,报告统计的相对较少。不过有jmeter的插件-JMeterPlugins,可以提供不少其他的报告,包括各种响应时间、吞吐率、线程等的变化曲线等
并且这个插件提供了命令行工具,可以将我们看到的各种曲线,各种报告统计成png图片,或者csv文件。这样我们就完全可以通过命令行来运行jmeter,生成jtl文件,然后在解析jtl文件,产生各种报告,或者展示到网页,或者插入到数据库,等等。
JMeterPluginsCMD Command Line Tool官方地址:https://jmeter-plugins.org/wiki/JMeterPluginsCMD/
2.安装
下载JMeterPlugins-Standard-1.2.0.zip和JMeterPlugins-Extras-1.2.0.zip,解压将里面的jar包复制到jmeter的lib/ext文件夹中即可。
3.用法
- 生成PNG:
JMeterPluginsCMD.bat --generate-png test.png --input-jtl results.jtl --plugin-type ResponseTimesOverTime --width 800 --height 600
或者
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-png ThreadsStateOverTime.png
二者本质一样的,JMeterPluginsCMD.bat文件内容
@echo off
java -jar %0\..\CMDRunner.jar --tool Reporter %*
- 生成CSV:
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-csv ThreadsStateOverTime.csv --input-jtl 1.jtl --plugin-type ThreadsStateOverTime
也可以一次性生成两个文件。下面是改命令的参数:
- –generate-png 指定png图片文件
- –generate-csv 指定csv文件名
- –input-jtl 指定要解析的jtl文件
- –plugin-type 指定要输出的数据类型,比如响应时间、cpu使用率、错误率等
使用–input-jtl merge-results.properties和–plugin-type MergeResults。merge-results.properties 文件位于 JMETER_HOME/bin 目录中。
4.Plugin Type Classes
需要安装相应的插件以在 CMD 中使用 Extras 插件。 插件提供解析下面这些数据的对象:
- AggregateReport = JMeter 的原生聚合报告,只能保存为 CSV
- SynthesisReport = JMeter 的原生汇总报告和聚合报告的混合,只能保存为 CSV
- ThreadsStateOverTime = 随时间推移的活动线程数
- BytesThroughputOverTime 吞吐率随线程变化曲线
- HitsPerSecond 每秒点击次数
- LatenciesOverTime 延迟时间
- PerfMon = PerfMon指标收集器
- DbMon = DbMon指标收集器,数据库,通过 sql 获取性能计数器
- JMXMon = JMXMon指标收集器,Java 管理扩展计数器
- ResponseCodesPerSecond 每秒响应代码
- ResponseTimesDistribution 响应时间分布
- ResponseTimesOverTime 响应时间随时间变化曲线
- ResponseTimesPercentiles 响应时间百分比
- ThroughputVsThreads 吞吐量与线程数
- TimesVsThreads = 响应时间 VS 线程
- TransactionsPerSecond 每秒事务数
- PageDataExtractorOverTime
- MergeResults = MergeResults命令行合并工具,简化两个或多个负载测试的比较,需要属性文件(如merge-results.properties)
5.示例
-
Jmeter脚本插件设置输入写入路径文件 -
非GUI命令行执行
F:\apache-jmeter-5.2.1\bin>jmeter -n -t Test.jmx -l result.jtl -j test.log
Creating summariser <summary>
Created the tree successfully using Test.jmx
Starting standalone test @ Fri Nov 05 23:35:08 CST 2021 (1636126508900)
Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
summary = 200 in 00:00:11 = 17.7/s Avg: 115 Min: 16 Max: 315 Err: 0 (0.00%)
Tidying up ... @ Fri Nov 05 23:35:20 CST 2021 (1636126520426)
... end of run
执行后指定路径下有设置的jtl文件
- 执行JMeterPluginCMD命令行
C:\Users\Administrator>java -jar F:\apache-jmeter-5.2.1\lib\ext\CMDRunner.jar --tool Reporter --generate-png PerfMon.png --input-jtl C:\Users\Administrator\Desktop\result3.jtl --plugin-type PerfMon
- 查看结果
JMETER_HOME/bin路径下
6.批量脚本
- Windows环境下
.bat脚本批处理生成png图片及csv文件
@echo off
set file=/Users/Desktop/TestLoad/result/result01.jtl
set ThreadsStateOverTime=/Users/Desktop
set BytesThroughputOverTime=/Users/Desktop
set HitsPerSecond=/Users/Desktop
set LatenciesOverTime=/Users/Desktop
set ResponseTimesOverTime=/Users/Desktop
set ResponseCodesPerSecond=/Users/Desktop
set ResponseTimesDistribution=/Users/Desktop
set ResponseTimesPercentiles=/Users/Desktop
set ThroughputVsThreads=/Users/Desktop
set TimesVsThreads=/Users/Desktop
set TransactionsPerSecond=/Users/Desktop
set PageDataExtractorOverTime=/Users/Desktop
set CMDRunnerPath=F:/apache-jmeter-5.2.1/lib/ext
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-png %ThreadsStateOverTime%/ThreadsStateOverTime.png --input-jtl %file% --plugin-type ThreadsStateOverTime
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-png %BytesThroughputOverTime%/BytesThroughputOverTime.png --input-jtl %file% --plugin-type BytesThroughputOverTime
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-png %HitsPerSecond%/HitsPerSecond.png --input-jtl %file% --plugin-type HitsPerSecond
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-png %LatenciesOverTime%/LatenciesOverTime.png --input-jtl %file% --plugin-type LatenciesOverTime
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-png %ResponseCodesPerSecond%/ResponseCodesPerSecond.png --input-jtl %file% --plugin-type ResponseCodesPerSecond
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-png %ResponseTimesDistribution%/ResponseTimesDistribution.png --input-jtl %file% --plugin-type ResponseTimesDistribution
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-png %ResponseTimesOverTime%/ResponseTimesOverTime.png --input-jtl %file% --plugin-type ResponseTimesOverTime
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-png %ResponseTimesPercentiles%/ResponseTimesPercentiles.png --input-jtl %file% --plugin-type ResponseTimesPercentiles
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-png %ThroughputVsThreads%/ThroughputVsThreads.png --input-jtl %file% --plugin-type ThroughputVsThreads
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-png %TimesVsThreads%/TimesVsThreads.png --input-jtl %file% --plugin-type TimesVsThreads
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-png %TransactionsPerSecond%/TransactionsPerSecond.png --input-jtl %file% --plugin-type TransactionsPerSecond
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-png %PageDataExtractorOverTime%/PageDataExtractorOverTime.png --input-jtl %file% --plugin-type PageDataExtractorOverTime
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-csv %ThreadsStateOverTime%/ThreadsStateOverTime.csv --input-jtl %file% --plugin-type ThreadsStateOverTime
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-csv %BytesThroughputOverTime%/BytesThroughputOverTime.csv --input-jtl %file% --plugin-type ThreadsStateOverTime
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-csv %HitsPerSecond%/HitsPerSecond.csv --input-jtl %file% --plugin-type BytesThroughputOverTime
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-csv %LatenciesOverTime%/LatenciesOverTime.csv --input-jtl %file% --plugin-type HitsPerSecond
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-csv %ResponseCodesPerSecond%/ResponseCodesPerSecond.csv --input-jtl %file% --plugin-type LatenciesOverTime
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-csv %ResponseTimesDistribution%/ResponseTimesDistribution.csv --input-jtl %file% --plugin-type ResponseCodesPerSecond
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-csv %ResponseTimesOverTime%/ResponseTimesOverTime.csv --input-jtl %file% --plugin-type ResponseTimesDistribution
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-csv %ResponseTimesPercentiles%/ResponseTimesPercentiles.csv --input-jtl %file% --plugin-type ResponseTimesOverTime
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-csv %ThroughputVsThreads%/ThroughputVsThreads.csv --input-jtl %file% --plugin-type ResponseTimesPercentiles
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-csv %TimesVsThreads%/TimesVsThreads.csv --input-jtl %file% --plugin-type ThroughputVsThreads
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-csv %TransactionsPerSecond%/TransactionsPerSecond.csv --input-jtl %file% --plugin-type TimesVsThreads
java -jar %CMDRunnerPath%/CMDRunner.jar --tool Reporter --generate-csv %PageDataExtractorOverTime%/TransactionsPerSecond.csv --input-jtl %file% --plugin-type TransactionsPerSecond
- Linux环境下
file= /Users/Desktop/TestLoad/result/result01.jtl
CMDRunnerPath=F:/apache-jmeter-5.2.1/lib/ext
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-png ${file%.*}_ThreadsStateOverTime.png --input-jtl $file --plugin-type ThreadsStateOverTime
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-png ${file%.*}_BytesThroughputOverTime.png --input-jtl $file --plugin-type BytesThroughputOverTime
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-png ${file%.*}_HitsPerSecond.png --input-jtl $file --plugin-type HitsPerSecond
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-png ${file%.*}_LatenciesOverTime.png --input-jtl $file --plugin-type LatenciesOverTime
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-png ${file%.*}_ResponseCodesPerSecond.png --input-jtl $file --plugin-type ResponseCodesPerSecond
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-png ${file%.*}_ResponseTimesDistribution.png --input-jtl $file --plugin-type ResponseTimesDistribution
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-png ${file%.*}_ResponseTimesOverTime.png --input-jtl $file --plugin-type ResponseTimesOverTime
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-png ${file%.*}_ResponseTimesPercentiles.png --input-jtl $file --plugin-type ResponseTimesPercentiles
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-png ${file%.*}_ThroughputVsThreads.png --input-jtl $file --plugin-type ThroughputVsThreads
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-png ${file%.*}_TimesVsThreads.png --input-jtl $file --plugin-type TimesVsThreads
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-png ${file%.*}_TransactionsPerSecond.png --input-jtl $file --plugin-type TransactionsPerSecond
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-png ${file%.*}_PageDataExtractorOverTime.png --input-jtl $file --plugin-type PageDataExtractorOverTime
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-csv ${file%.*}_AggregateReport.csv --input-jtl $file --plugin-type AggregateReport
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-csv ${file%.*}_ThreadsStateOverTime.csv --input-jtl $file --plugin-type ThreadsStateOverTime
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-csv ${file%.*}_BytesThroughputOverTime.csv --input-jtl $file --plugin-type BytesThroughputOverTime
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-csv ${file%.*}_HitsPerSecond.csv --input-jtl $file --plugin-type HitsPerSecond
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-csv ${file%.*}_LatenciesOverTime.csv --input-jtl $file --plugin-type LatenciesOverTime
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-csv ${file%.*}_ResponseCodesPerSecond.csv --input-jtl $file --plugin-type ResponseCodesPerSecond
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-csv ${file%.*}_ResponseTimesDistribution.csv --input-jtl $file --plugin-type ResponseTimesDistribution
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-csv ${file%.*}_ResponseTimesOverTime.csv --input-jtl $file --plugin-type ResponseTimesOverTime
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-csv ${file%.*}_ResponseTimesPercentiles.csv --input-jtl $file --plugin-type ResponseTimesPercentiles
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-csv ${file%.*}_ThroughputVsThreads.csv --input-jtl $file --plugin-type ThroughputVsThreads
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-csv ${file%.*}_TimesVsThreads.csv --input-jtl $file --plugin-type TimesVsThreads
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-csv ${file%.*}_TransactionsPerSecond.csv --input-jtl $file --plugin-type TransactionsPerSecond
java -jar $CMDRunnerPath/CMDRunner.jar --tool Reporter --generate-csv ${file%.*}_PageDataExtractorOverTime.csv --input-jtl $file --plugin-type PageDataExtractorOverTime
|