diff --git a/src/components/org/apache/jmeter/visualizers/backend/graphite/GraphiteBackendListenerClient.java b/src/components/org/apache/jmeter/visualizers/backend/graphite/GraphiteBackendListenerClient.java index a90c6d0..a66f1c6 100644 --- a/src/components/org/apache/jmeter/visualizers/backend/graphite/GraphiteBackendListenerClient.java +++ b/src/components/org/apache/jmeter/visualizers/backend/graphite/GraphiteBackendListenerClient.java @@ -20,14 +20,14 @@ import java.text.DecimalFormat; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.config.Arguments; @@ -68,21 +68,25 @@ private static final String METRIC_COUNT = "count"; //$NON-NLS-1$ private static final String METRIC_MIN_RESPONSE_TIME = "min"; //$NON-NLS-1$ private static final String METRIC_MAX_RESPONSE_TIME = "max"; //$NON-NLS-1$ + private static final String METRIC_AVG_RESPONSE_TIME = "avg"; //$NON-NLS-1$ private static final String METRIC_PERCENTILE = "pct"; //$NON-NLS-1$ private static final String METRIC_OK_COUNT = METRIC_OK_PREFIX+METRIC_SEPARATOR+METRIC_COUNT; private static final String METRIC_OK_MIN_RESPONSE_TIME = METRIC_OK_PREFIX+METRIC_SEPARATOR+METRIC_MIN_RESPONSE_TIME; private static final String METRIC_OK_MAX_RESPONSE_TIME = METRIC_OK_PREFIX+METRIC_SEPARATOR+METRIC_MAX_RESPONSE_TIME; + private static final String METRIC_OK_AVG_RESPONSE_TIME = METRIC_OK_PREFIX+METRIC_SEPARATOR+METRIC_AVG_RESPONSE_TIME; private static final String METRIC_OK_PERCENTILE_PREFIX = METRIC_OK_PREFIX+METRIC_SEPARATOR+METRIC_PERCENTILE; private static final String METRIC_KO_COUNT = METRIC_KO_PREFIX+METRIC_SEPARATOR+METRIC_COUNT; private static final String METRIC_KO_MIN_RESPONSE_TIME = METRIC_KO_PREFIX+METRIC_SEPARATOR+METRIC_MIN_RESPONSE_TIME; private static final String METRIC_KO_MAX_RESPONSE_TIME = METRIC_KO_PREFIX+METRIC_SEPARATOR+METRIC_MAX_RESPONSE_TIME; + private static final String METRIC_KO_AVG_RESPONSE_TIME = METRIC_KO_PREFIX+METRIC_SEPARATOR+METRIC_AVG_RESPONSE_TIME; private static final String METRIC_KO_PERCENTILE_PREFIX = METRIC_KO_PREFIX+METRIC_SEPARATOR+METRIC_PERCENTILE; private static final String METRIC_ALL_COUNT = METRIC_ALL_PREFIX+METRIC_SEPARATOR+METRIC_COUNT; private static final String METRIC_ALL_MIN_RESPONSE_TIME = METRIC_ALL_PREFIX+METRIC_SEPARATOR+METRIC_MIN_RESPONSE_TIME; private static final String METRIC_ALL_MAX_RESPONSE_TIME = METRIC_ALL_PREFIX+METRIC_SEPARATOR+METRIC_MAX_RESPONSE_TIME; + private static final String METRIC_ALL_AVG_RESPONSE_TIME = METRIC_ALL_PREFIX+METRIC_SEPARATOR+METRIC_AVG_RESPONSE_TIME; private static final String METRIC_ALL_PERCENTILE_PREFIX = METRIC_ALL_PREFIX+METRIC_SEPARATOR+METRIC_PERCENTILE; private static final String METRIC_ALL_HITS_COUNT = METRIC_HITS_PREFIX+METRIC_SEPARATOR+METRIC_COUNT; @@ -98,7 +102,7 @@ private boolean summaryOnly; private String rootMetricsPrefix; private String samplersList = ""; //$NON-NLS-1$ - private Set samplersToFilter; + private Pattern samplersToFilter; private Map okPercentiles; private Map koPercentiles; private Map allPercentiles; @@ -154,7 +158,7 @@ * @param metric {@link SamplerMetric} */ private void addMetrics(long timestampInSeconds, String contextName, SamplerMetric metric) { - + // See https://bz.apache.org/bugzilla/show_bug.cgi?id=57350 if(metric.getTotal() > 0) { graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_OK_COUNT, Integer.toString(metric.getSuccesses())); @@ -163,6 +167,7 @@ graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_ALL_HITS_COUNT, Integer.toString(metric.getHits())); if(metric.getSuccesses()>0) { graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_OK_MIN_RESPONSE_TIME, Double.toString(metric.getOkMinTime())); + graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_OK_AVG_RESPONSE_TIME, Double.toString(metric.getOkMean())); graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_OK_MAX_RESPONSE_TIME, Double.toString(metric.getOkMaxTime())); for (Map.Entry entry : okPercentiles.entrySet()) { graphiteMetricsManager.addMetric(timestampInSeconds, contextName, @@ -172,6 +177,7 @@ } if(metric.getFailures()>0) { graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_KO_MIN_RESPONSE_TIME, Double.toString(metric.getKoMinTime())); + graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_KO_AVG_RESPONSE_TIME, Double.toString(metric.getKoMean())); graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_KO_MAX_RESPONSE_TIME, Double.toString(metric.getKoMaxTime())); for (Map.Entry entry : koPercentiles.entrySet()) { graphiteMetricsManager.addMetric(timestampInSeconds, contextName, @@ -180,6 +186,7 @@ } } graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_ALL_MIN_RESPONSE_TIME, Double.toString(metric.getAllMinTime())); + graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_ALL_AVG_RESPONSE_TIME, Double.toString(metric.getAllMean())); graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_ALL_MAX_RESPONSE_TIME, Double.toString(metric.getAllMaxTime())); for (Map.Entry entry : allPercentiles.entrySet()) { graphiteMetricsManager.addMetric(timestampInSeconds, contextName, @@ -209,7 +216,8 @@ synchronized (LOCK) { for (SampleResult sampleResult : sampleResults) { getUserMetrics().add(sampleResult); - if(!summaryOnly && samplersToFilter.contains(sampleResult.getSampleLabel())) { + Matcher matcher = samplersToFilter.matcher(sampleResult.getSampleLabel()); + if( !summaryOnly && ( matcher.find() ) ) { SamplerMetric samplerMetric = getSamplerMetric(sampleResult.getSampleLabel()); samplerMetric.add(sampleResult); } @@ -256,11 +264,8 @@ Class clazz = Class.forName(graphiteMetricsSenderClass); this.graphiteMetricsManager = (GraphiteMetricsSender) clazz.newInstance(); graphiteMetricsManager.setup(graphiteHost, graphitePort, rootMetricsPrefix); - String[] samplers = samplersList.split(SEPARATOR); - samplersToFilter = new HashSet<>(); - for (String samplerName : samplers) { - samplersToFilter.add(samplerName); - } + samplersToFilter = 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); @@ -281,7 +286,6 @@ // Send last set of data before ending sendMetrics(); - samplersToFilter.clear(); graphiteMetricsManager.destroy(); super.teardownTest(context); }