You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在JMeter非GUI模式下获取RSP与TSP(无需HTML及手动解析JTL)

Got it, let's break this down—you're running JMeter headless on a server, dealing with multi-threaded tests, and need a quick way to grab both response times (RSP) and throughput (TSP) without HTML reports or loading JTLs locally. Perfect, here are two solid, actionable solutions:

1. Use JMeter's Built-In Aggregate Report for Out-of-the-Box CSV

The easiest way is to leverage JMeter's Aggregate Report listener, which natively outputs both response time metrics (average, median, 90th percentile, etc.) and throughput directly to a CSV. You can set this up either by modifying your test plan once, or via command line without touching the original script.

Option A: Modify Your Test Plan (One-Time Setup)

  • If you can temporarily open your test plan in JMeter GUI (even just once), add Listeners > Aggregate Report to your test plan.
  • Configure the listener: Check "Save Table Data" and set the output path to something like ./test_results.csv.
  • Run your test headless as usual:
    jmeter -n -t your_test_plan.jmx -l raw_results.jtl -j jmeter.log
    
    After the test finishes, test_results.csv will have all the RSP metrics you need (average, min, max, percentiles) plus a Throughput column (measured in requests/second) which is your TSP.

Option B: Dynamic Command-Line Setup (No Script Changes)

If you can't modify the original test plan, use a properties file to dynamically enable the Aggregate Report output:

  1. Create a file named aggregate_config.properties with these lines:
    aggregate_report.save.summarized_results=true
    aggregate_report.output_file=./test_results.csv
    
  2. Run your test with this properties file:
    jmeter -n -t your_test_plan.jmx -l raw_results.jtl -j jmeter.log -q aggregate_config.properties
    
    This will generate the same CSV with RSP and TSP metrics without altering your original test plan.

2. Custom CSV with JSR223 Listener (For Minimal, Tailored Output)

If you only need the bare essentials (e.g., just average response time and real-time throughput) and want to avoid extra columns, use a JSR223 Listener with Groovy (JMeter's fastest scripting language) to write directly to a CSV during the test.

  1. Add Listeners > JSR223 Listener to your test plan.
  2. Select "Groovy" as the language, then paste this script:
    // Initialize CSV header once at test start
    if (ctx.getThreadNum() == 0 && vars.get("csvInit") == null) {
        def csv = new File("./custom_metrics.csv")
        csv.write("Timestamp,Average_RSP_ms,Throughput_TSP_req_sec\n")
        vars.put("csvInit", "done")
    }
    
    // Calculate core metrics
    def totalRequests = ctx.getEngine().getSampleCount()
    def elapsedSeconds = (System.currentTimeMillis() - ctx.getEngine().getStartTime()) / 1000
    def throughput = totalRequests / elapsedSeconds
    def avgResponseTime = ctx.getEngine().getResultCollector().getAverage()
    
    // Write to CSV every 10 seconds (adjust interval as needed)
    def currentTime = new Date().format("yyyy-MM-dd HH:mm:ss")
    if (elapsedSeconds % 10 == 0 && vars.get("lastWrite") != elapsedSeconds.toString()) {
        def csv = new File("./custom_metrics.csv")
        csv.append("${currentTime},${avgResponseTime},${String.format("%.2f", throughput)}\n")
        vars.put("lastWrite", elapsedSeconds.toString())
    }
    
  3. Run your test headless—this script will write a row of RSP and TSP data every 10 seconds (you can adjust the interval by changing the % 10 value) to custom_metrics.csv.

Quick Notes:

  • Make sure JMeter's bin directory is in your system PATH, or use the full path to the jmeter executable.
  • Groovy is included with JMeter 3.2+, so no extra setup is needed for scripting.
  • The Aggregate Report's throughput metric is JMeter's standard calculation: total requests divided by the total elapsed time of the test, which aligns with standard TSP definitions.

内容的提问来源于stack exchange,提问作者Abhishek Prakash

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:22:29