【问题标题】:Setting sample_variables property at runtime在运行时设置 sample_variables 属性
【发布时间】:2016-07-06 20:27:12
【问题描述】:

有没有办法指定在运行时保存在输出文件中而不是 jmeter.properties 文件中的变量列表?

我目前在 jmeter.properties 文件中指定要保存在 sample_variables 中的变量列表,但这不允许为每个 JMeter 脚本指定不同的输出变量集,除非我不断更新 jmeter.properties 文件。

【问题讨论】:

    标签: variables jmeter runtime output


    【解决方案1】:

    我不知道在运行时更改 sample_variables 的方法。我知道的唯一解决方法是让 BeanShell 侦听器(或者可编程采样器/前置/后置处理器之一)写入自己的文件。例如:

    String filename = "myfile.txt";
    
    String message = "At " + System.currentTimeMillis() + " data is " + vars.get("myVar");
    
    FileOutputStream f = new FileOutputStream(filename, true);
    PrintStream p = new PrintStream(f); 
    this.interpreter.setOut(p); 
    print(message);
    f.close(); 
    

    您还可以在应保存变量时添加条件(例如,仅在特定采样器之后或仅在值更改时)。根据我的经验,使用 BeanShell 侦听器的解决方案在资源方面并不昂贵,因为无论运行线程的数量如何,它都是 1 个线程。具有可编程前/后处理器的解决方案通常更昂贵,除非您很少保存变量。

    【讨论】:

      【解决方案2】:

      您可以通过-J 命令行参数传递sample_variables(以及任何其他属性),例如:

      jmeter -Jsample_variables=foo -n -t script1.jmx
      jmeter -Jsample_variables=bar,baz -n -t script2.jmx
      

      另外,根据 JMeter 用户手册的Managing Properties 章节:

      当您需要修改 jmeter 属性时,请确保您不要修改 jmeter.properties 文件,而是从 jmeter.properties 中复制属性并在 user.properties 文件中修改其值。

      请参阅Apache JMeter Properties Customization Guide 文章,了解有关不同 JMeter 属性类型和使用它们的方式的综合信息

      【讨论】:

        猜你喜欢
        • 2011-05-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-02
        • 2011-04-17
        • 2016-09-12
        • 2015-03-11
        相关资源
        最近更新 更多