如何以编程方式从Jmeter生成响应时间图 [英] How to generate response times graph from Jmeter programmatically

查看:636
本文介绍了如何以编程方式从Jmeter生成响应时间图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下Java代码来运行JMeter.

I have the following java code to run JMeter.

import org.apache.jmeter.control.LoopController;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.threads.SetupThreadGroup;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.collections.HashTree;

public class HCTGameDay {

public static void main(String[] args){
    // Engine
    StandardJMeterEngine jm = new StandardJMeterEngine();
    // jmeter.properties
    JMeterUtils.loadJMeterProperties("/Users/rokumar/Desktop/jmeter.properties");

    HashTree hashTree = new HashTree();     

    // HTTP Sampler
    HTTPSampler httpSampler = new HTTPSampler();
    httpSampler.setDomain("www.linkedin.com");
    httpSampler.setPort(80);
    httpSampler.setPath("/");
    httpSampler.setMethod("GET");

    // Loop Controller
    TestElement loopCtrl = new LoopController();
    ((LoopController)loopCtrl).setLoops(1);
    ((LoopController)loopCtrl).addTestElement(httpSampler);
    ((LoopController)loopCtrl).setFirst(true);

    // Thread Group
    SetupThreadGroup threadGroup = new SetupThreadGroup();
    threadGroup.setNumThreads(1);
    threadGroup.setRampUp(1);
    threadGroup.setSamplerController((LoopController)loopCtrl);

    // Test plan
    TestPlan testPlan = new TestPlan("HCT TEST PLAN");

    hashTree.add("testPlan", testPlan);
    hashTree.add("loopCtrl", loopCtrl);
    hashTree.add("threadGroup", threadGroup);
    hashTree.add("httpSampler", httpSampler);       

    jm.configure(hashTree);

    jm.run();
    }
}

控制台输出中没有任何结果.响应时间等存储在哪里,如何以编程方式绘制响应时间,连接数和用户数图.

I do not get any results in the console output . Where are the response times etc. stored and how do I plot the graph of response times, number of connections, number of users programmatically.

推荐答案

jm.configure(hashTree)行之前添加以下代码

//add Summarizer output to get test progress in stdout like:
// summary =      2 in   1.3s =    1.5/s Avg:   631 Min:   290 Max:   973 Err:     0 (0.00%)
Summariser summer = null;
String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");
if (summariserName.length() > 0) {
summer = new Summariser(summariserName);
}


// Store execution results into a .jtl file
String logFile = jmeterHome + System.getProperty("line.separator") + "example.jtl";
ResultCollector logger = new ResultCollector(summer);
logger.setFilename(logFile);
testPlanTree.add(hashTree.getArray()[0], logger);

它将在JMeter安装的/bin文件夹中生成example.jtl文件,这是适用于分析,图形生成等的常规JMeter结果文件.

It will generate example.jtl file in /bin folder of your JMeter installation which is the usual JMeter result file suitable for analysis, graphs generation, etc.

请参见5种启动方式不使用JMeter GUI 的JMeter测试指南,以获取有关如何从常规代码和示例类中的Java代码运行JMeter测试的详细信息,网址为

See chapter 4.3 of 5 Ways To Launch a JMeter Test without Using the JMeter GUI guide for details on how to run JMeter test from Java code in general and example class at https://bitbucket.org/blazemeter/jmeter-from-code/ in particular for reference.

这篇关于如何以编程方式从Jmeter生成响应时间图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆