JMeter Integration with InfluxDB 2.0
Tags: testing, performance, docker, tutorial
Published: 2020-12-29 15:14:40

<!-- wp:paragraph -->
<p>In my last article, we have seen <a href="https://qainsights.com/jmeter-integration-with-influxdb-and-grafana-using-docker/" target="_blank" rel="noreferrer noopener">JMeter Integration with InfluxDB and Grafana using Docker</a>. We have used InfluxDB 1.8.3. This article talks about JMeter Integration with InfluxDB 2.0, because its little tricky in JMeter.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="h-what-s-new-in-influxdb-2-0">What's new in InfluxDB 2.0?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="h-prerequisites">Prerequisites</h2>
<!-- /wp:heading -->

<!-- wp:list {"ordered":true} -->
<ol><li>Docker</li><li>Apache JMeter 5.4</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>As usual, this setup has been tested in Windows 10 Pro. But it should work in other OS as well.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="h-let-s-get-started">Let's get started</h2>
<!-- /wp:heading -->

<!-- wp:heading {"level":3} -->
<h3 id="h-influxdb-2-0-set-up">InfluxDB 2.0 Set up</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>docker run -d -p 9002:8086 quay.io/influxdb/influxdb:v2.0.3</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>We are spinning up the container in the detached mode in the port 9002.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Launch http://localhost:9002 in your favorite browser.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Set up the initial user by filling the username, organization, and initial bucket name and then click on <strong>Continue</strong>. This will create a new bucket <code>jmeter</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":7993,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2020/12/image-48.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-48-1024x649.png" alt="JMeter Integration with InfluxDB 2.0" class="wp-image-7993"/></a><figcaption>JMeter Integration with InfluxDB 2.0</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Congratulations on spinning up InfluxDB 2.0.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":7994,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2020/12/image-49.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-49-1024x455.png" alt="InfluxDB 2.0" class="wp-image-7994"/></a><figcaption>InfluxDB 2.0</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>To integrate with JMeter, we need to token. Navigate to <strong>Data &gt; Tokens</strong>, click on <strong>Generate &gt; Read</strong>/<strong>Write Token</strong> as shown below.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":7995,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2020/12/image-50.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-50-1024x227.png" alt="Creating a Token" class="wp-image-7995"/></a><figcaption>Creating a Token</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Enter the description, select the scope for the bucket <code>jmeter</code> and then click on <strong>Save.</strong></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":7996,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2020/12/image-51.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-51.png" alt="Generate Token" class="wp-image-7996"/></a><figcaption>Generate Token</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Click on the token name to copy the generated token.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":7997,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2020/12/image-52.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-52.png" alt="Copy Token" class="wp-image-7997"/></a><figcaption>Copy Token</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:heading -->
<h2 id="h-jmeter-set-up">JMeter Set up</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Launch JMeter, and open the test plan which you will be executing. Add a backend listener by right clicking on <strong>Thread Group &gt; Add &gt; Listener &gt; Backend Listener.</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In this integration we are going to select <strong>InfluxDBRawBackendListenerClient</strong>. This is one of the <a href="https://qainsights.com/apache-jmeter-5-4-features/" target="_blank" rel="noreferrer noopener">JMeter 5.4 feature</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":7998,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image size-large"><a href="https://qainsights.com/wp-content/uploads/2020/12/image-53.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-53-1024x295.png" alt="Backend Listener" class="wp-image-7998"/></a><figcaption>Backend Listener</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong>InfluxDBRawBackendListenerClient </strong>uses more resources both in JMeter and InfluxDB as it streams all the results to InfluxDB. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Below are the parameters that needs to be configured.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":8002,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image size-large"><a href="https://qainsights.com/wp-content/uploads/2020/12/image-57.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-57-1024x106.png" alt="Backend Listener Parameters" class="wp-image-8002"/></a><figcaption>Backend Listener Parameters</figcaption></figure>
<!-- /wp:image -->

<!-- wp:list -->
<ul><li><strong>influxdbMetricsSender</strong> as <strong>org.apache.jmeter.visualizers.backend.influxdb.HttpMetricsSender</strong></li><li><strong>influxdbUrl </strong>as <strong>http://localhost:9002/api/v2/write?org=qainsights&amp;bucket=jmeter</strong></li><li><strong>influxdbToken </strong>as the value copied from InfluxDB</li><li><strong>measurement </strong>as <strong>jmeter </strong>(see <a href="https://docs.influxdata.com/influxdb/v2.0/reference/syntax/line-protocol/" target="_blank" rel="noreferrer noopener nofollow">Line Protocol</a>)</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Save your test plan and start your JMeter test in CLI mode.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Go to Influx and navigate to <strong>Data Explorer</strong>. You could see your JMeter performance stats real time.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8000,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2020/12/image-55.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-55-1024x453.png" alt="Data Explorer" class="wp-image-8000"/></a><figcaption>Data Explorer</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Below is the configuration if you would like to use the Backend Listener Client. Please make sure that you have added <code>influxdbToken</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":8001,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image size-large"><a href="https://qainsights.com/wp-content/uploads/2020/12/image-56.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-56-1024x337.png" alt="Influx DB Backend Listener" class="wp-image-8001"/></a><figcaption>Influx DB Backend Listener</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>For the above configuration&nbsp;, you will get percentile measurements in InfluxDB.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8004,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2020/12/image-58.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-58-1024x479.png" alt="InfluxDB 2.0 Visualization" class="wp-image-8004"/></a><figcaption>InfluxDB 2.0 Visualization</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:heading -->
<h2 id="h-grafana-integration">Grafana Integration</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>If you do not want to use InfluxDB 2.0 visualization, you can integrate in Grafana. Launch Grafana and navigate to <strong>Data Sources</strong>. Check my last post about <a href="https://qainsights.com/jmeter-integration-with-influxdb-and-grafana-using-docker/" target="_blank" rel="noreferrer noopener">how to add Data Source in Grafana</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In the <strong>Data Sources </strong>page, configure the below settings.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8006,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2020/12/image-60.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-60.png" alt="Grafana and InfluxDB 2.0 Integration" class="wp-image-8006"/></a><figcaption>Grafana and InfluxDB 2.0 Integration</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>The difference between Influx 1.8.3 vs Influx 2.0 set up is: the Query Language and Connection details.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Please make sure you select <strong>Flux </strong>as <strong>Query Language</strong> and the connection is the docker container IP address.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To read the docker container IP address, enter the below command.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>docker container inspect &lt;container_id&gt; | grep -i ipaddress</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p><code>container_id</code> is the influx db container ID.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The default port of InfluxDB is 8086.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Also, make sure you are configuring the <code>Token</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Click on <strong>Save &amp; Test </strong>which will retrieve the bucket(s).</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Navigate to <strong>Explore </strong>and select the database and enter the below query and hit <strong>Run Query</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>from(bucket: "jmeter")
  |&gt; range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |&gt; filter(fn: (r) =&gt; r&#91;"_measurement"] == "jmeter")
  |&gt; filter(fn: (r) =&gt; r&#91;"_field"] == "pct95.0")
  |&gt; filter(fn: (r) =&gt; r&#91;"transaction"] == "T00_Home" or r&#91;"transaction"] == "T10_Search" or r&#91;"transaction"] == "T20_AddToCart")
  |&gt; filter(fn: (r) =&gt; r&#91;"application"] == "InfluxDB 2.0 Integration")
  |&gt; filter(fn: (r) =&gt; r&#91;"statut"] == "ok")
  |&gt; aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |&gt; yield(name: "mean")</code></pre>
<!-- /wp:code -->

<!-- wp:image {"id":8007,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image size-large"><a href="https://qainsights.com/wp-content/uploads/2020/12/image-61.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-61-1024x541.png" alt="Grafana Visualization" class="wp-image-8007"/></a><figcaption>Grafana Visualization</figcaption></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2 id="h-final-words">Final Words</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The JMeter help documentation instructions didn't help me in integrating InfluxDB 2.0. But the above configuration makes the integration easy.</p>
<!-- /wp:paragraph -->