JMeterLearner
JMeterLearner

Reputation: 11

Backend Listener in Distributed Mode in JMeter

My JMeter version is 5.5

I am using Backend Listener --> InfluxDB --> Grafana Dashboard to display real time result of the execution. My test plan includes multiple thread groups and one backend listener. I have stored influxdb url in property file and passing it to backend listener as ${__P(influxdburl)}.

When I run the test from single machine backend Listener detects the variable and sends result to grafana, but when I run it in distributed mode it does not recognize this value from property file (I tried to pass it in other samplers to check if I can access it there, it works).

When I pass hard coded value for influxdb url instead of trying to access it from property file then backend listener is working fine.

Now I am trying to generate custom backend listener which should take this value from property file (as other elements are able to get values except for backend listener) and send results to influxdb and eventually to grafana.

Here is what I tried so far, access the value in user parameters / pre processor sampler and then send that variable to backend listener which did not work.

I am trying to write backend listener in beanshell listener and

My code looks like this

import org.apache.jmeter.visualizers.backend.BackendListener;
import org.apache.jmeter.config.Arguments;
import org.apache.jorphan.collections.HashTree;

HashTree hashTree = new HashTree();

BackendListener backendListener = new BackendListener();
Arguments arguments = new Arguments();

arguments.addArgument("influxdbMetricsSender", "org.apache.jmeter.visualizers.backend.influxdb.HttpMetricsSender");
arguments.addArgument("influxdbUrl", "myinfluxurl:port/write?db=dbname&p=somevalue");
arguments.addArgument("application", "myapplication");
arguments.addArgument("measurement", "jmeter");
arguments.addArgument("summaryOnly", "false");
arguments.addArgument("samplersRegex", ".*");
arguments.addArgument("percentiles", "90;95;99");
arguments.addArgument("testTitle","mytestname");
arguments.addArgument("eventTags"," ");

backendListener.setArguments(arguments);

hashTree.add(backendListener;

This code does not send test result to grafana. I need to know what am I doing wrong here and how can I improve it? As far as I believe I should not generate new HashTree object and use the from the current testplan, but I am not sure how to do it (searched for JMeterContext but could not find any method related to get current test plan)

Upvotes: 1

Views: 337

Answers (2)

George Li
George Li

Reputation: 1

In distributed mode the individual jmeter workers send the samples to the jmeter master/controller. Any backend listener configured on the jmeter workers are ignored. The backend listener must be configured on the jmeter master in order for you to send metrics to influxdb. This means must configure the influxdb backend listener in the test plan itself BEFORE execute your test.

Upvotes: 0

Ivan G
Ivan G

Reputation: 2707

I cannot reproduce your issue using JMeter 5.6.3 and fail to see anything related to Backend Listener in changelog so my expectation is that it should work on JMeter 5.5 as well:

enter image description here

With regards to your approach of adding the listener programmatically:

  1. It will not work as the HashTree is initialized and loaded before your Beanshell code is executed
  2. In general using Beanshell for scripting is discouraged, you should use JSR223 Test Elements and Groovy language if you want to extend your test with some scripting. See Apache Groovy: What Is Groovy Used For? article for more details.

If you want to build your test plan from code check out Building a Test Plan Programmatically guide

Upvotes: 0

Related Questions