In my last article, we have seen JMeter Integration with InfluxDB and Grafana using Docker. We have used InfluxDB 1.8.3. This article talks about JMeter Integration with InfluxDB 2.0, because its little tricky in JMeter.
Table of Contents
What’s new in InfluxDB 2.0?
InfluxDB 2.0 Open Source is GA last month (November 2020). InfluxDB 2.0 contains single binary to get started, and its secure by default, meaning every request accompanied by a token, new query language Flux and more.
Prerequisites
- Docker
- Apache JMeter 5.4
As usual, this setup has been tested in Windows 10 Pro. But it should work in other OS as well.
Let’s get started
InfluxDB 2.0 Set up
You cannot install InfluxDB 2.0 natively in Windows OS. You must rely on Docker (at this moment of writing). To spin up InfluxDB 2.0 container, use the below command.
docker run -d -p 9002:8086 quay.io/influxdb/influxdb:v2.0.3
We are spinning up the container in the detached mode in the port 9002.
Launch http://localhost:9002 in your favorite browser.
Set up the initial user by filling the username, organization, and initial bucket name and then click on Continue. This will create a new bucket jmeter
.
Congratulations on spinning up InfluxDB 2.0.
To integrate with JMeter, we need to token. Navigate to Data > Tokens, click on Generate > Read/Write Token as shown below.
Enter the description, select the scope for the bucket jmeter
and then click on Save.
Click on the token name to copy the generated token.
JMeter Set up
Launch JMeter, and open the test plan which you will be executing. Add a backend listener by right clicking on Thread Group > Add > Listener > Backend Listener.
In this integration we are going to select InfluxDBRawBackendListenerClient. This is one of the JMeter 5.4 feature.
InfluxDBRawBackendListenerClient uses more resources both in JMeter and InfluxDB as it streams all the results to InfluxDB.
Below are the parameters that needs to be configured.
- influxdbMetricsSender as org.apache.jmeter.visualizers.backend.influxdb.HttpMetricsSender
- influxdbUrl as http://localhost:9002/api/v2/write?org=qainsights&bucket=jmeter
- influxdbToken as the value copied from InfluxDB
- measurement as jmeter (see Line Protocol)
Save your test plan and start your JMeter test in CLI mode.
Go to Influx and navigate to Data Explorer. You could see your JMeter performance stats real time.
Below is the configuration if you would like to use the Backend Listener Client. Please make sure that you have added influxdbToken
.
For the above configuration , you will get percentile measurements in InfluxDB.
Grafana Integration
If you do not want to use InfluxDB 2.0 visualization, you can integrate in Grafana. Launch Grafana and navigate to Data Sources. Check my last post about how to add Data Source in Grafana.
In the Data Sources page, configure the below settings.
The difference between Influx 1.8.3 vs Influx 2.0 set up is: the Query Language and Connection details.
Please make sure you select Flux as Query Language and the connection is the docker container IP address.
To read the docker container IP address, enter the below command.
docker container inspect <container_id> | grep -i ipaddress
container_id
is the influx db container ID.
The default port of InfluxDB is 8086.
Also, make sure you are configuring the Token
.
Click on Save & Test which will retrieve the bucket(s).
Navigate to Explore and select the database and enter the below query and hit Run Query.
from(bucket: "jmeter")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "jmeter")
|> filter(fn: (r) => r["_field"] == "pct95.0")
|> filter(fn: (r) => r["transaction"] == "T00_Home" or r["transaction"] == "T10_Search" or r["transaction"] == "T20_AddToCart")
|> filter(fn: (r) => r["application"] == "InfluxDB 2.0 Integration")
|> filter(fn: (r) => r["statut"] == "ok")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: "mean")
Final Words
InfluxDB 2.0 integration with JMeter powers up your performance test monitoring to the next level. By having powerful dashboards and monitoring them while the test is running helps you to debug the issues quicker.
The JMeter help documentation instructions didn’t help me in integrating InfluxDB 2.0. But the above configuration makes the integration easy.
Hi Navven, thanks for the good instructions.
With the Raw listener I get my transactions per sampler as wanted, with the influxlistener I only get an “all” checkbox with status and transaction, no detail steps.
Any idea why? I tried to place the listener in different places in the testpla, but no difference.
Regards Thomas
In the Backend Listener, chnge SummaryOnly field to false. Then, You will get all the data in Influx.
Hi Naveen,
Can you guide me how to configure Gatling with InfluxDB2 and Grafana. As I learned as of now we cannot input the Gatling data straight away to InfluxDB2 and we need the Telegraf plugin.
I configured telegraf->Influxdb2->Grafan but still I didn’t get the data from Gatling. I configured the gatling.conf as instructed by the official realtime monitoring guide by Gatling.
Note : I’m running telegraf, influxdb2 and Grafana on a docker.
Hi there
It seems I’ve been looking for answers all over the Internet. So the question is:
how could I transfer custom metrics from JMeter to InfluxDB? For example, if I use JSR223 Sampler and there is calculating of some variable. I need to take this variable and push it through Backend Listener to InfluxDB. Would you give me some ideas of doing this?
Hi Alex,
vars.put(“Metric”,”pass the fields which you want to store along with timestamp”)
Example
vars.put(“Metric”,”MeasurementName, usercount=01, usersfailed=8, userspassed=10, ${__time()}000000″)
Then, invoke InfluxDB endpoint with post method.
http://localhost:8086//api/v2/write?org=${porg}&bucket=${pbucket}
${Metric} — Body
As part of the headers, send the below info
Authorization Token adadad&^%&*
Content-Type text/plain;charset=utf-8
Any dashboard available to visualize the Jmeter metrics scraped through influx 2.0 ? Old dashboards no longer with influx 2.0. Any thoughts ?
You can’t re-use the old queries as the query language is different in the new version. Please use the queries mentioned in the below link.
https://raw.githubusercontent.com/influxdata/community-templates/master/apache_jmeter/apache_jmeter.yml
I hope this helps.
This was by far the most relevant and easier to follow guide for the latest influxdb buckets. Thanks Naveen.
Thanks for the tutorial!
It inspired me to share my solution:
https://github.com/kschepkin/perf-jmeter/blob/main/README-EN.MD
My example has ready-made dashboards with metrics and the ability to run in parallel from multiple VMs. I’d appreciate it if you’d appreciate it!
What is admin token which is created by default? What is the jmeter token that we create?
Hi ..Thanks for the excellent explanation. I am currently facing one issue, not getting “Jmeter” in measurement in influx db on data explorer page . Any idea how this can be resolved