Dynatrace Backend Listener for JMeter
Tags: performance, testing, tutorial, webperf
Published: 2021-01-04 15:13:01

<!-- wp:paragraph -->
<p>Couple months ago Dynatrace had released brand-new backend listener for JMeter which streams the performance stats from JMeter to Dynatrace. This backend listener sends the JMeter metrics to the Dynatrace environment via <a href="https://www.dynatrace.com/support/help/how-to-use-dynatrace/metrics/metric-ingestion/metric-ingestion-protocol/" target="_blank" rel="noreferrer noopener nofollow">MINT</a>. This blog post features about the Dynatrace Backend Listener for JMeter, how to integrate it, create dashboards and more.</p>
<!-- /wp:paragraph -->

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

<!-- wp:paragraph -->
<p>Before we get started with the integration of Dynatrace backend listener in JMeter, let us fulfill the prerequisites.</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Dynatrace account. It is free to <a href="https://www.dynatrace.com/trial/" target="_blank" rel="noreferrer noopener nofollow">sign up</a>.</li><li>Sample demo app which is already integrated with Dynatrace</li><li>Apache JMeter (the latest version)</li><li>Sample JMeter test plan to execute a simple load test against the demo app.</li></ol>
<!-- /wp:list -->

<!-- wp:heading {"level":3} -->
<h3 id="h-step-1-download-jar-for-jmeter"><strong>Step 1 - Download JAR</strong> <strong>for JMeter</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Download the JMeter plugin from the <a href="https://github.com/dynatrace-oss/jmeter-dynatrace-plugin/releases" target="_blank" rel="noreferrer noopener nofollow">Dynatrace OSS repo</a>. Download the latest version from the <strong>Assets </strong>as shown below.</p>
<!-- /wp:paragraph -->

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

<!-- wp:paragraph -->
<p>If you want to build it on your own, clone the repo <code>https://github.com/dynatrace-oss/jmeter-dynatrace-plugin.git</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>cd</code> into the folder and run <code>.\gradlew build</code> in Powershell.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This will create build the jar for JMeter. Navigate to <code>jmeter-dynatrace-plugin\build\libs</code>. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Copy the <code>jmeter-dynatrace-plugin-1.3-SNAPSHOT.jar</code> to JMeter's <code>lib\ext</code> folder.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Launch JMeter and open the test plan which you are going to execute. Right click on the <strong>Thread Group &gt; Add &gt; Listener &gt; Backend Listener</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Select the implementation as <code>com.dynatrace.jmeter.plugins.MintBackendListener</code> as shown below.</p>
<!-- /wp:paragraph -->

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

<!-- wp:paragraph -->
<p>Below are the default properties of Mint Backend Listener.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8080,"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-91.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-91-1024x298.png" alt="" class="wp-image-8080"/></a></figure></div>
<!-- /wp:image -->

<!-- wp:heading {"level":3} -->
<h3 id="h-step-2-configuring-jmeter-backend-listener"><strong>Step 2 - Configuring JMeter Backend Listener</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>To stream the JMeter performance stats to Dynatrace, the listener leverages <a href="https://www.dynatrace.com/support/help/dynatrace-api/environment-api/metric-v2/post-ingest-metrics/" target="_blank" rel="noreferrer noopener nofollow">Metric Ingest URL</a>, API Token, test and transaction dimensions.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The URL would be your Dynatrace URL e.g. <code><code>https://&lt;environment_id&gt;.live.dynatrace.com</code>/api/v2/metrics/ingest</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The <strong>Environment ID </strong>can  be copied from the browser URL once you logged into your Dynatrace.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To generate a token, login into Dynatrace account, navigate to <strong>Settings &gt; Integration &gt; Dynatrace API</strong>. Under <strong>My Dynatrace API Tokens </strong>click on <strong>Generate token </strong>as shown below.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8081,"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-92.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-92-1024x358.png" alt="" class="wp-image-8081"/></a></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Enter a name for your token, select <code>Ingest metrics</code> under <strong>API v2</strong> and then click on <strong>Generate </strong>button.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8082,"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-93.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-93.png" alt="" class="wp-image-8082"/></a></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Click on <strong>Copy </strong>button and store the token in a secured place, because you cannot see it again in near future.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8083,"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-94.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-94.png" alt="" class="wp-image-8083"/></a></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Dimensions can be specified using <strong>key=value </strong>pairs. There are two dimensions: test and transactions for test and test steps (samplers) related metrics respectively.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Following are the MINT metrics will be published during the test execution.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Below are the <strong>testDimensions </strong>will be generated when the test is running.</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li><code>jmeter.usermetrics.startedthreads</code>: the number of started threads</li><li><code>jmeter.usermetrics.finishedthreads</code>: the number of finished threads</li><li><code>jmeter.usermetrics.minactivethreads</code>: the minimum number of active threads</li><li><code>jmeter.usermetrics.maxactivethreads</code>: the maximum number of active threads</li><li><code>jmeter.usermetrics.meanactivethreads</code>: the arithmetic mean of active threads</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>E.g.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>c.d.j.p.MintMetricSender: addMetric(jmeter.usermetrics.minactivethreads,testname=Dynatrace-JMeter.jmx gauge,1.0 1609460965970)
c.d.j.p.MintMetricSender: addMetric(jmeter.usermetrics.maxactivethreads,testname=Dynatrace-JMeter.jmx gauge,1.0 1609460965971)
c.d.j.p.MintMetricSender: addMetric(jmeter.usermetrics.meanactivethreads,testname=Dynatrace-JMeter.jmx gauge,1.0 1609460965971)
c.d.j.p.MintMetricSender: addMetric(jmeter.usermetrics.startedthreads,testname=Dynatrace-JMeter.jmx gauge,1.0 1609460965971)
c.d.j.p.MintMetricSender: addMetric(jmeter.usermetrics.finishedthreads,testname=Dynatrace-JMeter.jmx gauge,1.0 1609460965971)</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Below are the <strong>transactionDimensions</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li><code>jmeter.usermetrics.transaction.mintime</code>: the minimal elapsed time for requests within sliding window</li><li><code>jmeter.usermetrics.transaction.maxtime</code>: the maximal elapsed time for requests within sliding window</li><li><code>jmeter.usermetrics.transaction.meantime</code>: the arithmetic mean of the elapsed time</li><li><code>jmeter.usermetrics.transaction.receivedbytes</code>: the number of received bytes</li><li><code>jmeter.usermetrics.transaction.sentbytes</code>: the number of sent bytes</li><li><code>jmeter.usermetrics.transaction.hits</code>: the number of hits to the server</li><li><code>jmeter.usermetrics.transaction.error</code>: the number of failed requests</li><li><code>jmeter.usermetrics.transaction.success</code>: the number of successful requests</li><li><code>jmeter.usermetrics.transaction.count</code>: the total number of requests</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>E.g.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>addMetric(jmeter.usermetrics.transaction.count,transaction=T00_HomePage,dt.entity.service=SERVICE-XXXXXXXXXXXXXXX gauge,1.0 1609460965969)
addMetric(jmeter.usermetrics.transaction.success,transaction=T00_HomePage,dt.entity.service=SERVICE-XXXXXXXXXXXXXXX gauge,1.0 1609460965969)
addMetric(jmeter.usermetrics.transaction.error,transaction=T00_HomePage,dt.entity.service=SERVICE-XXXXXXXXXXXXXXX gauge,0.0 1609460965969)
addMetric(jmeter.usermetrics.transaction.hits,transaction=T00_HomePage,dt.entity.service=SERVICE-XXXXXXXXXXXXXXXX gauge,1.0 1609460965969)
addMetric(jmeter.usermetrics.transaction.mintime,transaction=T00_HomePage,dt.entity.service=SERVICE-XXXXXXXXXXXXXXX gauge,26.0 1609460965969)</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Dimensions are optional. But the metric and payload is required. </p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre id="block-663906e6-386e-4129-a17f-ae7cf295085d" class="wp-block-code"><code>jmeter.usermetrics.transaction.count,transaction=T00_HomePagegauge,1.0 1609460965969</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>After adding all the values in the backend listener, this is how it looks. Instead of hard coding, all the values will be read from the test plan variables.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8084,"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-95.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-95-1024x301.png" alt="" class="wp-image-8084"/></a></figure></div>
<!-- /wp:image -->

<!-- wp:heading {"level":4} -->
<h4 id="h-how-to-get-the-service-id">How to get the Service ID?</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In Dynatrace, navigate to Application and services, click on the service name. In the browser URL, you can fetch the Service ID. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>E.g. <code>https://&lt;environment_id&gt;.live.dynatrace.com/#newservices/serviceOverview;id=&lt;SERVICE-XXXXXXXXXXXXXXXX</code>&gt;<code>;gtf=-2h;gf=all</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Copy the service id including the string <code>SERVICE-</code> and 17 length string to JMeter.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 id="h-step-3-test-execution">Step 3 - Test Execution</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Start your test in CLI mode. While the test is running, go to <strong>Dynatrace</strong>, click on <strong>Applications </strong>or <strong>Transactions and services </strong>make sure you are seeing the load test traffic in Dynatrace. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I am running a demo app in Flask at port 7000. If the integration between the demo app and Dynatrace is valid, you will see the traffic as shown below.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8085,"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-96.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-96-1024x371.png" alt="" class="wp-image-8085"/></a></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>To view the JMeter metrics, go to <strong>Dashboard &gt; Create Dashboard</strong>, enter a valid name and then click on <strong>Create</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Drag-and-drop the <strong>Custom Chart </strong>to the dashboard and then click on <strong>Configure </strong>custom chart. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Click on <strong>Try it out</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8086,"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-97.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-97-1024x139.png" alt="" class="wp-image-8086"/></a></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Start typing <code>jmeter</code> as shown below. Dynatrace will list out all the metrics available.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8087,"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-98.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-98.png" alt="" class="wp-image-8087"/></a></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Enter <code>jmeter.usermetrics.maxactivethreads</code> to get the maximum active threads and then click on <strong>Add Metric</strong> if you would like to add more metrics, else click on <strong>Run query</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8088,"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-99.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-99-1024x525.png" alt="" class="wp-image-8088"/></a></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>You can customize the graph and colors under the <strong>Settings</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8089,"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-100.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-100.png" alt="" class="wp-image-8089"/></a></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Here is how it looks for <strong>Single Value</strong> visualization.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8090,"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-101.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-101-1024x312.png" alt="" class="wp-image-8090"/></a></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>To pin the above chart, click on <strong>Pin to dashboard</strong> and enter the title and then click on <strong>Pin</strong>, then click on <strong>Open Dashboard</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8091,"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-102.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-102.png" alt="" class="wp-image-8091"/></a></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Here is the dashboard view.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8092,"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-103.png"><img src="https://qainsights.com/wp-content/uploads/2020/12/image-103.png" alt="" class="wp-image-8092"/></a></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Here is my sample dashboard which I customized. Beautiful, isn't it?</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8096,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2021/01/image.png"><img src="https://qainsights.com/wp-content/uploads/2021/01/image.png" alt="" class="wp-image-8096"/></a></figure></div>
<!-- /wp:image -->

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

<!-- wp:paragraph -->
<p>JMeter backend listener for Dynatrace streams the performance stats straight to Dynatrace. It will be helpful to compare the head-to-head metrics between Dynatrace and JMeter. Often, I present both the metrics to the architects, but with this integration, I save time and effort by migrating JMeter metrics to my dashboard.</p>
<!-- /wp:paragraph -->