Integrate web API performance monitoring in JMeter


Web-based APIs in server-side applications allow other clients such as mobile or AppMon Clients to use their functionality. Tools like JMeter or SoapUI typically perform functional testing of those APIs. You can continuously monitor API performance with AppMon's Web API support.


Although you can monitor WebAPI load tests produced by JMeter, it is recommend not to do so.

Load tests usually produce huge amount of data in a short period of time. That may lead to significant Performance Warehouse size increase, as well as longer processing time or some data loss.

If you want to use JMeter as a load testing tool, pass only NA X-dynaTrace header parameter, without passing TR parameter (see description here), and analyze results using the Load tests feature. Doing this omits Test Automation feature processing, but generates PurePaths for all WebAPI calls produced by JMeter.



This tutorial shows you how to:

  • Create a JMeter script that tests a web service.
  • Analyze the web service performance.

The tutorial accesses an easyTravel URI (/services/JourneyService/findJourneys) where you can find journeys filtered by start date, end date, and location, and get a list of journeys in XML. If you have easyTravel running on your machine you can try to access http://localhost:8080/services/JourneyService/findJourneys?destination=New%20York&fromDate=1406282400000&toDate=1437818400000 for a list of journeys to New York. If this call fails, make sure you have easyTravel started and running on port 8080.


This example uses the system profile supplied with easyTravel. If you prefer to use your own system profile, make sure you have the Servlet sensor enabled as shown in the following:

Create the JMeter test plan, and name it Test the findJourneys Interface.

Make sure the Run Thread Groups consecutively check box is selected in Test Plan properties. This ensures test run registration always executes before running the test.

Register a new test run of the Web API category, This is done by a REST call to the AppMon server. The REST call executes a POST request which registers a test run.

In JMeter, create a new ThreadGroup and name it Register Test Run. Add an instance of HTTP Authorization Manager. This is done because server REST interface access is protected with basic authentication:


You can pass additional metadata during registering. See REST Interfaces for Test Automation for more information.

Add a HTTP Header Manager to set the default Content-Type to text/xml:

Add an HTTP Request Sampler that POSTs to the testrun URI to register a new test run. To do this, right-click the thread group and select Add > Sampler > HTTP Request. You can specify the body of this request either as XML or JSO.

This example uses XML to register a test run for Web API tests, running on platform Windows and for version 5.1.1500.1234:

<testRun category="webapi" platform="Windows" versionMajor="5" versionMinor="1" versionRevision="1500" versionBuild="1234" />

The XML response returned for this call contains the test run ID. Use this as the id attribute value. This tags all requests belonging to this test run. It also contains an attribute called href that contains a URI that fetches the results for this test run.

Extract the test run ID to tag all the HTTP requests to the findJourneys service. Use an XPath Extractor to get the id attribute and save it in the DT_TESTRUN_ID variable.

To make fetching the results easier, add a second XPath extract for the href attribute:


These variables are only available within this sample.

These variables are used in subsequent steps of the test plan. Use JMeter properties to pass them along. To do this, add an instance of the BeanShell PostProcessor with the following code. The code uses the variables DT_TESTRUN_ID and TESTRUN_RESULT_HREF as properties in other steps of the test plan.

import org.apache.jmeter.util.JMeterUtils;
JMeterUtils.setProperty("testrunId", vars.get("DT_TESTRUN_ID"));
JMeterUtils.setProperty("href", vars.get("TESTRUN_RESULT_HREF"));

Create the actual test request to the web service. First, add a new ThreadGroup to the test plan and call it Call findJourneys Service.
Add an HTTP Request sampler and name it Execute request to findJourneys. Configure it as shown in the following, which assumes the easyTravel customer frontend is running at localhost:8080. Adapt the host/port as needed.

To tag the request with the test run ID, add a BeanShell PreProcessor to the HTTP Request and call it AppMonTagging. This Preprocessor reads the set properties and sets the test run ID as part of the X-dynatrace header tag:

An HTTP Header Manager is needed for this step. Just having the header manager is enough, so no further configuration is needed:

Use the following script to set the right header tag.

import org.apache.jmeter.util.JMeterUtils;
String trid=JMeterUtils.getProperty("testrunId");
String NA=sampler.getName();
String VU=ctx.getThreadGroup().getName() + ctx.getThreadNum();
sampler.getHeaderManager().add(new org.apache.jmeter.protocol.http.control.Header("X-dynaTrace","NA=" +NA+";TR="+trid+";RC=200" ));

The final preprocessor configuration should look as follows.

This executes the web service call using the right X-dynatrace tag to have this request show up as a Web API test in the Test Automation Dashlet. The request uses NA field sampler name, which is the name of the API shown in the dashlet. the TR field contains the test run ID obtaining by registering the test run the RC field contains the expected response code.

You can now looks at the results on JMeterTo do this, add a Results Tree to the Test Plan.

You can now run the test plan. Use the Play button in the toolbar to run the test plan.


Remember that easyTravel must be running.

The View Results tree shows individual test steps, the sampler, and the request and response data, as shown in the following.

Run the test a few more times to have more data in the Test Automation Dashlet.

Once the request executes, you can see request results in the Test Automation Dashlet. In the AppMon Client, open the Test Automation Dashlet from the Cockpit.

With the dashlet open, adjust the time filter to the last 30 minutes, to make it easier to find the requests you just executed. This screen shot shows the request made, a list of metrics as well as a historic chart of metric values:


Sample script