Skip to content

Commit

Permalink
Custom properties (#13)
Browse files Browse the repository at this point in the history
* Set Operation name to test name

* Ability to send custom properties
  • Loading branch information
adrianmo authored Jul 21, 2020
1 parent 1d41f74 commit 0d94c4c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ Then, in the Parameters table, configure the following attributes.
| *samplersList* | Optional list of samplers separated by a semi-colon (`;`) that the listener will collect and send metrics to Application Insights. If the list is empty, the listener will not filter samplers and send metrics from all of them. Defaults to an empty string. | No |
| *useRegexForSamplerList* | If set to `true` the `samplersList` will be evaluated as a regex to filter samplers. Defaults to `false`. | No |


*Example of configuration:*

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

#### Custom properties

You can add custom data to your metrics by adding properties starting with `ai.`, for example, you might want to provide information related to your environment with the property `ai.environment` and value `staging`.

### Visualization

Test result metrics are available in the **requests** dimension of your Application Insights instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import org.apache.jmeter.visualizers.backend.BackendListenerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -35,6 +37,7 @@ public class AzureBackendClient extends AbstractBackendListenerClient {
private static final String KEY_LIVE_METRICS = "liveMetrics";
private static final String KEY_SAMPLERS_LIST = "samplersList";
private static final String KEY_USE_REGEX_FOR_SAMPLER_LIST = "useRegexForSamplerList";
private static final String KEY_CUSTOM_PROPERTIES_PREFIX = "ai.";

/**
* Default argument values.
Expand All @@ -60,6 +63,11 @@ public class AzureBackendClient extends AbstractBackendListenerClient {
*/
private String testName;

/**
* Custom properties.
*/
private Map<String, String> customProperties = new HashMap<String, String>();

/**
* Whether to send metrics to the Live Metrics Stream.
*/
Expand Down Expand Up @@ -103,6 +111,14 @@ public void setupTest(BackendListenerContext context) throws Exception {
samplersList = context.getParameter(KEY_SAMPLERS_LIST, DEFAULT_SAMPLERS_LIST).trim();
useRegexForSamplerList = context.getBooleanParameter(KEY_USE_REGEX_FOR_SAMPLER_LIST, DEFAULT_USE_REGEX_FOR_SAMPLER_LIST);

Iterator<String> iterator = context.getParameterNamesIterator();
while (iterator.hasNext()) {
String paramName = iterator.next();
if (paramName.startsWith(KEY_CUSTOM_PROPERTIES_PREFIX)) {
customProperties.put(paramName, context.getParameter(paramName));
}
}

TelemetryConfiguration config = TelemetryConfiguration.createDefault();
config.setInstrumentationKey(context.getParameter(KEY_INSTRUMENTATION_KEY));
telemetryClient = new TelemetryClient(config);
Expand All @@ -122,6 +138,7 @@ public void setupTest(BackendListenerContext context) throws Exception {

private void trackRequest(String name, SampleResult sr) {
Map<String, String> properties = new HashMap<String, String>();
properties.putAll(customProperties);
properties.put("Bytes", Long.toString(sr.getBytesAsLong()));
properties.put("SentBytes", Long.toString(sr.getSentBytes()));
properties.put("ConnectTime", Long.toString(sr.getConnectTime()));
Expand Down

0 comments on commit 0d94c4c

Please sign in to comment.