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.
Requirements
- AppMon with the Pre-Production edition license
- easyTravel demo application
- JMeter. This tutorial uses JMeter 3.3.
Goal
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 (/result.jsf?dest=New+York
) 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/result.jsf?dest=New+York for a list of journeys to New York. If this call fails, make sure you have easyTravel started and running on port 8080.
Steps
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 for the required Agent Group/Tier. Also, you'll have to specify data of your app instead of easyTravel.
Instead of creating test script manually, you can download and use the sample script.
1. Create the test plan
- In JMeter, click the New icon, to create a new test plan. Set the name as Test findJourneys.
- 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.

2. Configure a REST call to AppMon Server
Now we need to configure REST call to the AppMon Server, which will create a test run of the web API category. The REST call executes a POST request which registers a test run.
Right-click your test plan and select Add > Threads (Users) > ThreadGroup to create a new ThreadGroup. Set the name as Register Test Run.
Add an instance of HTTP Authorization Manager. You need it because server REST interface access is protected with basic authentication.
- Right-click your thread group, and select Add > Config Element > HTTP Authorization Manager.
- Click Add to create a new authorization, and specify the parameters:
- Base URL: URL of AppMon Frontend Server. In this tutorial it's
https://localhost:8021
. - Username, Password: Account data of user with sufficient permissions. In this tutorial it's both
admin
. - Realm: Dynatrace Server
- Base URL: URL of AppMon Frontend Server. In this tutorial it's

You can pass additional metadata during registering. See REST Interfaces for Test Automation for more information.
Set the content type to application/json:
- Right-click your thread group, and select Add > Config Element > HTTP Header Manager
- Click Add to and specify the following:
- Name:
content-type
. - Value:
application/json
.
- Name:

Add an HTTP Request Sampler, which will execute the POST request to register a new test run:
- Right-click your thread group and select Add > Sampler > HTTP Request.
- Set the name as Register test run.
- At the Basic tab, specify the following:
- Protocol:
https
- Server Name or IP:
localhost
- Port number:
8021
- Method:
POST
- Path: depending on the AppMon version:
-
AppMon 2017 May
api/v2/profiles/easyTravel/testruns
-
AppMon 2018 April
api/v3/profiles/easyTravel/testruns
-
AppMon 2017 May
- Select Redirect automatically checkbox.
- Protocol:
- At the Advanced tab, specify the following:
- Implementation: Java
- At the Body tab, specify the JSON body of the request. This example registers a test run for web API tests, running on Linux:
{
"platform": "Linux",
"category": "webapi",
"additionalMetaData": {}
}

The JSON 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.
This configuration presumes that you have AppMon Server running on the same machine you're working, with default port settings. If it's not your case, replace protocol, server name, and port settings with those of your AppMon Server.
2. Extract the test run parameters
You need them to tag HTTP request to the findJourneys
service. You will need the ID of the test run, and the href
property.
These variables are only available within this sample.
Right-click Register test run and select Add > Post Processors > JSON Extractor.
Specify parameters as follows:
- Reference Name:
DT_TESTRUN_ID
- XPath query:
$.id
- Default Value:
NOT FOUND

To get the href
, ddd another JSON Extractor, and specify the following:
- Reference Name:
TESRUN_RESULT_HREF
- XPath query:
$.hfer
- Default Value:
NOT FOUND

Now we need to pass the extracted variables along. Right-click Register test run and select Add > Post Processors > BeanShell PostProcessor. Copy the code below in it. 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"));
3. Configure the test request to easyTravel
How we'll send the test request to the findJourneys
service of the easyTravel application.
Right-click your test plan and select Add > Threads (Users) > ThreadGroup to create a new ThreadGroup. Set the name as Call findJourneys Service.

Add an HTTP Request Sampler, which will execute the POST request to register a new test run:
- Right-click your thread group and select Add > Sampler > HTTP Request.
- Set the name as Execute request to findJourneys.
- At the Basic tab, specify the following:
- Server Name or IP:
localhost
- Port number:
8080
- Method:
GET
- Path:
/result.jsf?dest=New+York
- Select Follow Redirects checkbox.
- Server Name or IP:

This configuration presumes that you have easyTravel running on the same machine you're working, with default port settings. If it's not your case, replace server name, and port settings with those of your easyTravel.
Now, tag the request with the test run ID.
-
Right-click Execute request to findJourneys thread group, and select Add > Pre Processors > BeanShell PreProcessor.
-
Set the name as AppMonTagging.
-
Copy the script below to the pre-processor.
import org.apache.jmeter.util.JMeterUtils; String trid=JMeterUtils.getProperty("testrunId"); String NA=sampler.getName(); String VU=ctx.getThreadGroup().getName() + ctx.getThreadNum(); sampler.getHeaderManager().clear(); sampler.getHeaderManager().add(new org.apache.jmeter.protocol.http.control.Header("X-dynaTrace","NA=" +NA+";TR="+trid+";RC=200" ));
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 Result 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 also need An HTTP Header Manager here. Just having the header manager is enough, no further configuration is needed. Right-click Execute request to findJourneys thread group, and select Add > Config Element > HTTP Header Manager
4. Add result tree
This one is needed to see the result to the test run in JMEter. Right-click your test plan and select Add > Listeners > View Results Tree.
5. Run the test and view results
Click the Play button in the toolbar to run the test plan.
easyTravel must be running at the time.
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.
Once the request executes, you can see request results in the Test Result dashlet in the AppMon Client.
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: