Search in sources :

Example 1 with SamplerMetric

use of org.apache.jmeter.visualizers.backend.SamplerMetric in project jmeter by apache.

the class GraphiteBackendListenerClient method handleSampleResults.

@Override
public void handleSampleResults(List<SampleResult> sampleResults, BackendListenerContext context) {
    boolean samplersToFilterMatch;
    synchronized (LOCK) {
        UserMetric userMetrics = getUserMetrics();
        for (SampleResult sampleResult : sampleResults) {
            userMetrics.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);
                }
            }
            getSamplerMetric(CUMULATED_METRICS).addCumulated(sampleResult);
        }
    }
}
Also used : UserMetric(org.apache.jmeter.visualizers.backend.UserMetric) Matcher(java.util.regex.Matcher) SampleResult(org.apache.jmeter.samplers.SampleResult) SamplerMetric(org.apache.jmeter.visualizers.backend.SamplerMetric)

Example 2 with SamplerMetric

use of org.apache.jmeter.visualizers.backend.SamplerMetric in project jmeter by apache.

the class InfluxdbBackendListenerClient method handleSampleResults.

@Override
public void handleSampleResults(List<SampleResult> sampleResults, BackendListenerContext context) {
    synchronized (LOCK) {
        UserMetric userMetrics = getUserMetrics();
        for (SampleResult sampleResult : sampleResults) {
            userMetrics.add(sampleResult);
            Matcher matcher = samplersToFilter.matcher(sampleResult.getSampleLabel());
            if (!summaryOnly && matcher.find()) {
                SamplerMetric samplerMetric = getSamplerMetricInfluxdb(sampleResult.getSampleLabel());
                samplerMetric.add(sampleResult);
            }
            SamplerMetric cumulatedMetrics = getSamplerMetricInfluxdb(CUMULATED_METRICS);
            cumulatedMetrics.addCumulated(sampleResult);
        }
    }
}
Also used : UserMetric(org.apache.jmeter.visualizers.backend.UserMetric) Matcher(java.util.regex.Matcher) SampleResult(org.apache.jmeter.samplers.SampleResult) SamplerMetric(org.apache.jmeter.visualizers.backend.SamplerMetric)

Example 3 with SamplerMetric

use of org.apache.jmeter.visualizers.backend.SamplerMetric in project jmeter by apache.

the class InfluxdbBackendListenerClient method sendMetrics.

private void sendMetrics() {
    synchronized (LOCK) {
        for (Map.Entry<String, SamplerMetric> entry : metricsPerSampler.entrySet()) {
            SamplerMetric metric = entry.getValue();
            if (entry.getKey().equals(CUMULATED_METRICS)) {
                addCumulatedMetrics(metric);
            } else {
                addMetrics(AbstractInfluxdbMetricsSender.tagToStringValue(entry.getKey()), metric);
            }
            // We are computing on interval basis so cleanup
            metric.resetForTimeInterval();
        }
    }
    UserMetric userMetrics = getUserMetrics();
    // For JMETER context
    StringBuilder tag = new StringBuilder(80);
    tag.append(TAG_APPLICATION).append(applicationName);
    tag.append(TAG_TRANSACTION).append("internal");
    tag.append(userTag);
    StringBuilder field = new StringBuilder(80);
    field.append(METRIC_MIN_ACTIVE_THREADS).append(userMetrics.getMinActiveThreads()).append(',');
    field.append(METRIC_MAX_ACTIVE_THREADS).append(userMetrics.getMaxActiveThreads()).append(',');
    field.append(METRIC_MEAN_ACTIVE_THREADS).append(userMetrics.getMeanActiveThreads()).append(',');
    field.append(METRIC_STARTED_THREADS).append(userMetrics.getStartedThreads()).append(',');
    field.append(METRIC_ENDED_THREADS).append(userMetrics.getFinishedThreads());
    influxdbMetricsManager.addMetric(measurement, tag.toString(), field.toString());
    influxdbMetricsManager.writeAndSendMetrics();
}
Also used : UserMetric(org.apache.jmeter.visualizers.backend.UserMetric) SamplerMetric(org.apache.jmeter.visualizers.backend.SamplerMetric) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with SamplerMetric

use of org.apache.jmeter.visualizers.backend.SamplerMetric in project jmeter by apache.

the class GraphiteBackendListenerClient method sendMetrics.

/**
 * Send metrics to Graphite
 */
protected void sendMetrics() {
    // Need to convert millis to seconds for Graphite
    long timestampInSeconds = TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    synchronized (LOCK) {
        for (Map.Entry<String, SamplerMetric> entry : getMetricsPerSampler().entrySet()) {
            final String key = entry.getKey();
            final SamplerMetric metric = entry.getValue();
            if (key.equals(CUMULATED_METRICS)) {
                addMetrics(timestampInSeconds, ALL_CONTEXT_NAME, metric);
            } else {
                addMetrics(timestampInSeconds, AbstractGraphiteMetricsSender.sanitizeString(key), metric);
            }
            // We are computing on interval basis so cleanup
            metric.resetForTimeInterval();
        }
    }
    UserMetric userMetric = getUserMetrics();
    graphiteMetricsManager.addMetric(timestampInSeconds, TEST_CONTEXT_NAME, METRIC_MIN_ACTIVE_THREADS, Integer.toString(userMetric.getMinActiveThreads()));
    graphiteMetricsManager.addMetric(timestampInSeconds, TEST_CONTEXT_NAME, METRIC_MAX_ACTIVE_THREADS, Integer.toString(userMetric.getMaxActiveThreads()));
    graphiteMetricsManager.addMetric(timestampInSeconds, TEST_CONTEXT_NAME, METRIC_MEAN_ACTIVE_THREADS, Integer.toString(userMetric.getMeanActiveThreads()));
    graphiteMetricsManager.addMetric(timestampInSeconds, TEST_CONTEXT_NAME, METRIC_STARTED_THREADS, Integer.toString(userMetric.getStartedThreads()));
    graphiteMetricsManager.addMetric(timestampInSeconds, TEST_CONTEXT_NAME, METRIC_FINISHED_THREADS, Integer.toString(userMetric.getFinishedThreads()));
    graphiteMetricsManager.writeAndSendMetrics();
}
Also used : UserMetric(org.apache.jmeter.visualizers.backend.UserMetric) SamplerMetric(org.apache.jmeter.visualizers.backend.SamplerMetric) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with SamplerMetric

use of org.apache.jmeter.visualizers.backend.SamplerMetric in project jmeter by apache.

the class InfluxdbBackendListenerClient method getSamplerMetricInfluxdb.

private SamplerMetric getSamplerMetricInfluxdb(String sampleLabel) {
    SamplerMetric samplerMetric = metricsPerSampler.get(sampleLabel);
    if (samplerMetric != null) {
        return samplerMetric;
    }
    SamplerMetric newSamplerMetric = new SamplerMetric();
    SamplerMetric oldValue = metricsPerSampler.putIfAbsent(sampleLabel, newSamplerMetric);
    if (oldValue != null) {
        newSamplerMetric = oldValue;
    }
    return newSamplerMetric;
}
Also used : SamplerMetric(org.apache.jmeter.visualizers.backend.SamplerMetric)

Aggregations

SamplerMetric (org.apache.jmeter.visualizers.backend.SamplerMetric)5 UserMetric (org.apache.jmeter.visualizers.backend.UserMetric)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Matcher (java.util.regex.Matcher)2 SampleResult (org.apache.jmeter.samplers.SampleResult)2 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1