Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.apache.jmeter.visualizers.backend.SamplerMetric;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Graphite based Listener using Pickle Protocol
Expand Down Expand Up @@ -99,6 +101,7 @@ public class GraphiteBackendListenerClient extends AbstractBackendListenerClient
private boolean summaryOnly;
private String rootMetricsPrefix;
private String samplersList = ""; //$NON-NLS-1$
private boolean useRegexpForSamplersList;
private Set<String> samplersToFilter;
private Map<String, Float> okPercentiles;
private Map<String, Float> koPercentiles;
Expand All @@ -110,6 +113,8 @@ public class GraphiteBackendListenerClient extends AbstractBackendListenerClient
private ScheduledExecutorService scheduler;
private ScheduledFuture<?> timerHandle;

private Pattern pattern;

public GraphiteBackendListenerClient() {
super();
}
Expand Down Expand Up @@ -207,12 +212,22 @@ public void setSamplersList(String samplersList) {
@Override
public void handleSampleResults(List<SampleResult> sampleResults,
BackendListenerContext context) {
boolean samplersToFilterMatch;
synchronized (LOCK) {
for (SampleResult sampleResult : sampleResults) {
getUserMetrics().add(sampleResult);
if(!summaryOnly && samplersToFilter.contains(sampleResult.getSampleLabel())) {
SamplerMetric samplerMetric = getSamplerMetric(sampleResult.getSampleLabel());
samplerMetric.add(sampleResult);

if(!summaryOnly) {
if (useRegexpForSamplersList) {
Matcher matcher = pattern.matcher(sampleResult.getSampleLabel());
samplersToFilterMatch = matcher.matches();
} else {
samplersToFilterMatch = samplersToFilter.contains(sampleResult.getSampleLabel());
}
if (samplersToFilterMatch) {
SamplerMetric samplerMetric = getSamplerMetric(sampleResult.getSampleLabel());
samplerMetric.add(sampleResult);
}
}
SamplerMetric cumulatedMetrics = getSamplerMetric(CUMULATED_METRICS);
cumulatedMetrics.add(sampleResult);
Expand All @@ -228,6 +243,7 @@ public void setupTest(BackendListenerContext context) throws Exception {
graphitePort = context.getIntParameter("graphitePort", DEFAULT_PLAINTEXT_PROTOCOL_PORT);
summaryOnly = context.getBooleanParameter("summaryOnly", true);
samplersList = context.getParameter("samplersList", "");
useRegexpForSamplersList = context.getBooleanParameter("useRegexpForSamplersList", false);
rootMetricsPrefix = context.getParameter("rootMetricsPrefix", DEFAULT_METRICS_PREFIX);
String percentilesAsString = context.getParameter("percentiles", DEFAULT_METRICS_PREFIX);
String[] percentilesStringArray = percentilesAsString.split(SEPARATOR);
Expand Down Expand Up @@ -260,9 +276,13 @@ public void setupTest(BackendListenerContext context) throws Exception {
Class<?> clazz = Class.forName(graphiteMetricsSenderClass);
this.graphiteMetricsManager = (GraphiteMetricsSender) clazz.newInstance();
graphiteMetricsManager.setup(graphiteHost, graphitePort, rootMetricsPrefix);
String[] samplers = samplersList.split(SEPARATOR);
samplersToFilter = new HashSet<>();
Collections.addAll(samplersToFilter, samplers);
if (!useRegexpForSamplersList) {
String[] samplers = samplersList.split(SEPARATOR);
samplersToFilter = new HashSet<>();
Collections.addAll(samplersToFilter, samplers);
} else {
pattern = Pattern.compile(samplersList);
}
scheduler = Executors.newScheduledThreadPool(MAX_POOL_SIZE);
// Don't change this as metrics are per second
this.timerHandle = scheduler.scheduleAtFixedRate(this, ONE_SECOND, ONE_SECOND, TimeUnit.SECONDS);
Expand Down Expand Up @@ -297,6 +317,7 @@ public Arguments getDefaultParameters() {
arguments.addArgument("rootMetricsPrefix", DEFAULT_METRICS_PREFIX);
arguments.addArgument("summaryOnly", "true");
arguments.addArgument("samplersList", "");
arguments.addArgument("useRegexpForSamplersList", "false");
arguments.addArgument("percentiles", DEFAULT_PERCENTILES);
return arguments;
}
Expand Down
Binary file modified xdocs/images/screenshots/backend_listener.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion xdocs/usermanual/component_reference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3539,7 +3539,8 @@ By default, a Graphite implementation is provided.
<property name="graphitePort" required="Yes">Graphite or InfluxDB (with Graphite plugin enabled) server port, defaults to <code>2003</code>. Note <code>PickleGraphiteMetricsSender</code> (port <code>2004</code>) can only talk to Graphite server.</property>
<property name="rootMetricsPrefix" required="Yes">Prefix of metrics sent to backend. Defaults to "<code>jmeter</code>."</property>
<property name="summaryOnly" required="Yes">Only send a summary with no detail. Defaults to <code>true</code>.</property>
<property name="samplersList" required="Yes">Semicolon separated list of samplers for which you want to report metrics to backend.</property>
<property name="samplersList" required="Yes">Semicolon separated list of samplers or a regular expression for which you want to report metrics to backend.</property>
<property name="useRegexpForSamplersList" required="Yes">Use a regular expression to get the list of samplers for which you want to report metrics to backend. Defaults to <code>false</code>.</property>
<property name="percentiles" required="Yes">The percentiles you want to send to backend. List must be semicolon separated.</property>
</properties>
<p>Read <a href="realtime-results.html" >this</a> for more details.</p>
Expand Down