Skip to content

Commit

Permalink
Report metrics to requests dimension
Browse files Browse the repository at this point in the history
Signed-off-by: Adrián Moreno <adrian@morenomartinez.com>
  • Loading branch information
adrianmo committed Feb 11, 2020
1 parent d93d9bb commit 007b07a
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 32 deletions.
69 changes: 52 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,67 @@ A JMeter plug-in that enables you to send test results to Azure Application Insi

### Description

JMeter Backend Azure is a JMeter plugin enabling you to send test results to an Azure Application Insights. This plugin is inspired in the [Elasticsearch](https://github.com/delirius325/jmeter-elasticsearch-backend-listener) and [Kafka](https://github.com/rahulsinghai/jmeter-backend-listener-kafka) backend listener plugins.

### Build

- To build the artifact, execute below Maven command. Make sure `JAVA_HOME` is set properly.
JMeter Backend Azure is a JMeter plugin enabling you to send test results to an Azure Application Insights.

The following test results metrics are exposed by the plugin.

- TestStartTime
- SampleStartTime
- SampleEndTime
- ResponseCode
- Duration
- URL
- SampleLabel
- SampleCount
- ErrorCount
- Bytes
- SentBytes
- ConnectTime
- IdleTime
- ThreadName
- GrpThreads
- AllThreads

### Plugin installation

Once you have built or downloaded the plugin JAR file from the [releases](https://github.com/adrianmo/jmeter-backend-azure/releases) section,
move the JAR to your `$JMETER_HOME/lib/ext`.

```bash
mvn clean package
mv target/jmeter.backendlistener.azure-VERSION.jar $JMETER_HOME/lib/ext/
```

- Move the resulting JAR to your `JMETER_HOME/lib/ext`.
Then, restart JMeter and the plugin should be loaded.

```bash
mv target/jmeter.backendlistener.azure-VERSION.jar $JMETER_HOME/lib/ext/
```
### JMeter configuration

To make JMeter send test result metrics to Azure Application Insights, in your **Test Pan**, right click on
**Thread Group** > Add > Listener > Backend Listener, and choose `io.github.adrianmo.jmeter.backendlistener.azure.AzureBackendClient` as `Backend Listener Implementation`.
Then, specify the metric name and the Application Insights instrumentation key as a parameter as shown in image below.

- Restart JMeter
![Screenshot of configuration](docs/configuration.png "Screenshot of JMeter configuration")

### Configuring jmeter-backend-azure plug-in
### Visualization

- In your **Test Pan**, right click on **Thread Group** > Add > Listener > Backend Listener
- Choose `io.github.adrianmo.jmeter.backendlistener.azure.AzureBackendClient` as `Backend Listener Implementation`.
- Specify the Application Insights instrumentation key as a parameter as shown in image below:
Test result metrics are available in the **requests** dimension of your Application Insights instance.
In the image you can see an example of how you can visualize the duration of the requests made during your test run.

![Screenshot of configuration](docs/configuration.png "Screenshot of configuration")
![Request duration](docs/requestduration.png "Screenshot of test requests duration")

## Contributing

Feel free to contribute by branching and making pull requests, or simply by suggesting ideas through the "Issues" tab.
Feel free to contribute by forking and making pull requests, or simply by suggesting ideas through the
[Issues](https://github.com/adrianmo/jmeter-backend-azure/issues) section.

### Build

You can make changes to the plugin and build your own JAR file to test changes. To build the artifact,
execute below Maven command. Make sure `JAVA_HOME` is set properly.

```bash
mvn clean package
```

---

This plugin is inspired in the [Elasticsearch](https://github.com/delirius325/jmeter-elasticsearch-backend-listener) and [Kafka](https://github.com/rahulsinghai/jmeter-backend-listener-kafka) backend listener plugins.
Binary file modified docs/configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/requestduration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.adrianmo</groupId>
<artifactId>jmeter.backendlistener.azure</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>A JMeter plug-in that enables you to send test results to Azure Monitor.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.microsoft.applicationinsights.TelemetryClient;
import com.microsoft.applicationinsights.TelemetryConfiguration;
import com.microsoft.applicationinsights.internal.util.MapUtil;
import com.microsoft.applicationinsights.telemetry.MetricTelemetry;
import com.microsoft.applicationinsights.telemetry.Duration;
import com.microsoft.applicationinsights.telemetry.RequestTelemetry;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.threads.JMeterContextService;
Expand All @@ -18,6 +19,7 @@
public class AzureBackendClient extends AbstractBackendListenerClient {

private TelemetryClient client;
private static final String METRIC_NAME = "metricName";
private static final String INSTRUMENTATION_KEY = "instrumentationKey";

public AzureBackendClient() {
Expand All @@ -27,6 +29,7 @@ public AzureBackendClient() {
@Override
public Arguments getDefaultParameters() {
Arguments arguments = new Arguments();
arguments.addArgument(METRIC_NAME, "jmeter");
arguments.addArgument(INSTRUMENTATION_KEY, "");
return arguments;
}
Expand All @@ -38,8 +41,14 @@ public void setupTest(BackendListenerContext context) throws Exception {
super.setupTest(context);
}

private void trackMetric(String name, Double value, SampleResult sr) {
private void trackRequest(String name, SampleResult sr) {
Map<String, String> properties = new HashMap<String, String>();
properties.put("Bytes", Long.toString(sr.getBytesAsLong()));
properties.put("SentBytes", Long.toString(sr.getSentBytes()));
properties.put("ConnectTime", Long.toString(sr.getConnectTime()));
properties.put("ErrorCount", Integer.toString(sr.getErrorCount()));
properties.put("IdleTime", Double.toString(sr.getIdleTime()));
properties.put("Latency", Double.toString(sr.getLatency()));
properties.put("BodySize", Long.toString(sr.getBodySizeAsLong()));
properties.put("TestStartTime", Long.toString(JMeterContextService.getTestStartTime()));
properties.put("SampleStartTime", Long.toString(sr.getStartTime()));
Expand All @@ -50,24 +59,20 @@ private void trackMetric(String name, Double value, SampleResult sr) {
properties.put("ResponseCode", sr.getResponseCode());
properties.put("GrpThreads", Integer.toString(sr.getGroupThreads()));
properties.put("AllThreads", Integer.toString(sr.getAllThreads()));
properties.put("SampleCount", Integer.toString(sr.getSampleCount()));

MetricTelemetry metric = new MetricTelemetry(name, value);
metric.setCount(sr.getSampleCount());
metric.setTimestamp(new Date(sr.getTimeStamp()));
MapUtil.copy(properties, metric.getProperties());
client.trackMetric(metric);
Date timestamp = new Date(sr.getTimeStamp());
Duration duration = new Duration(sr.getTime());
RequestTelemetry req = new RequestTelemetry(name, timestamp, duration, sr.getResponseCode(), sr.getErrorCount() == 0);
req.setUrl(sr.getURL());
MapUtil.copy(properties, req.getProperties());
client.trackRequest(req);
}

@Override
public void handleSampleResults(List<SampleResult> results, BackendListenerContext context) {
for (SampleResult sr : results) {
trackMetric("Bytes", (double)sr.getBytesAsLong(), sr);
trackMetric("SentBytes", (double)sr.getSentBytes(), sr);
trackMetric("ConnectTime", (double)sr.getConnectTime(), sr);
trackMetric("ErrorCount", (double)sr.getErrorCount(), sr);
trackMetric("IdleTime", (double)sr.getIdleTime(), sr);
trackMetric("Latency", (double)sr.getLatency(), sr);
trackMetric("ResponseTime", (double)sr.getTime(), sr);
trackRequest(context.getParameter(METRIC_NAME), sr);
}
}

Expand Down

0 comments on commit 007b07a

Please sign in to comment.