Bug 62276 - InfluxDBBackendListenerClient / GraphiteBackendListenerClient : Add sent and received bytes to metrics

Contributed by UbikLoadPack
Bugzilla Id: 62276

git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1828834 13f79535-47bb-0310-9956-ffa450edef68

Former-commit-id: 00e8d37406
This commit is contained in:
Philippe Mouawad 2018-04-10 16:59:36 +00:00
parent 08f7a252c7
commit 4a01c8c76a
7 changed files with 81 additions and 7 deletions

View File

@ -62,6 +62,8 @@ public class SamplerMetric {
private int failures;
private int hits;
private Map<ErrorMetric, Integer> errors = new HashMap<>();
private long sentBytes;
private long receivedBytes;
/**
@ -106,6 +108,18 @@ public class SamplerMetric {
koResponsesStats.addValue(time);
}
addHits(result);
addNetworkData(result);
}
/**
* Increment traffic metrics. A Parent sampler cumulates its children metrics.
* @param result SampleResult
*/
private void addNetworkData(SampleResult result) {
if (!TransactionController.isFromTransactionController(result)) {
sentBytes += result.getSentBytes();
receivedBytes += result.getBytesAsLong();
}
}
/**
@ -115,7 +129,7 @@ public class SamplerMetric {
private void addHits(SampleResult res) {
SampleResult[] subResults = res.getSubResults();
if (!TransactionController.isFromTransactionController(res)) {
hits += 1;
hits += 1;
}
for (SampleResult subResult : subResults) {
addHits(subResult);
@ -143,6 +157,8 @@ public class SamplerMetric {
successes = 0;
failures = 0;
hits = 0;
sentBytes = 0;
receivedBytes = 0;
}
/**
@ -310,4 +326,18 @@ public class SamplerMetric {
public Map<ErrorMetric, Integer> getErrors() {
return errors;
}
/**
* @return the sentBytes
*/
public long getSentBytes() {
return sentBytes;
}
/**
* @return the receivedBytes
*/
public long getReceivedBytes() {
return receivedBytes;
}
}

View File

@ -83,7 +83,10 @@ public class GraphiteBackendListenerClient extends AbstractBackendListenerClient
private static final String METRIC_KO_PREFIX = "ko"; //$NON-NLS-1$
private static final String METRIC_ALL_PREFIX = "a"; //$NON-NLS-1$
private static final String METRIC_HITS_PREFIX = "h"; //$NON-NLS-1$
private static final String METRIC_SENT_BYTES_PREFIX = "sb"; //$NON-NLS-1$
private static final String METRIC_RECEIVED_BYTES_PREFIX = "rb"; //$NON-NLS-1$
private static final String METRIC_BYTES = "bytes"; //$NON-NLS-1$
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$
@ -109,6 +112,8 @@ public class GraphiteBackendListenerClient extends AbstractBackendListenerClient
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;
private static final String METRIC_ALL_SENT_BYTES = METRIC_SENT_BYTES_PREFIX+METRIC_SEPARATOR+METRIC_BYTES;
private static final String METRIC_ALL_RECEIVED_BYTES = METRIC_RECEIVED_BYTES_PREFIX+METRIC_SEPARATOR+METRIC_BYTES;
private static final long SEND_INTERVAL = JMeterUtils.getPropDefault("backend_graphite.send_interval", 1);
private static final int MAX_POOL_SIZE = 1;
@ -203,6 +208,10 @@ public class GraphiteBackendListenerClient extends AbstractBackendListenerClient
METRIC_ALL_COUNT, Integer.toString(metric.getTotal()));
graphiteMetricsManager.addMetric(timestampInSeconds, contextName,
METRIC_ALL_HITS_COUNT, Integer.toString(metric.getHits()));
graphiteMetricsManager.addMetric(timestampInSeconds, contextName,
METRIC_ALL_SENT_BYTES, Long.toString(metric.getSentBytes()));
graphiteMetricsManager.addMetric(timestampInSeconds, contextName,
METRIC_ALL_RECEIVED_BYTES, Long.toString(metric.getReceivedBytes()));
if(metric.getSuccesses()>0) {
graphiteMetricsManager.addMetric(timestampInSeconds,
contextName, METRIC_OK_MIN_RESPONSE_TIME,
@ -288,7 +297,7 @@ public class GraphiteBackendListenerClient extends AbstractBackendListenerClient
}
}
SamplerMetric cumulatedMetrics = getSamplerMetric(CUMULATED_METRICS);
cumulatedMetrics.add(sampleResult);
cumulatedMetrics.add(sampleResult);
}
}
}

View File

@ -76,6 +76,8 @@ public class InfluxdbBackendListenerClient extends AbstractBackendListenerClient
private static final String METRIC_AVG = "avg=";
private static final String METRIC_HIT = "hit=";
private static final String METRIC_SENT_BYTES = "sb=";
private static final String METRIC_RECEIVED_BYTES = "rb=";
private static final String METRIC_PCT_PREFIX = "pct";
private static final String METRIC_MAX_ACTIVE_THREADS = "maxAT=";
@ -180,13 +182,13 @@ public class InfluxdbBackendListenerClient extends AbstractBackendListenerClient
*/
private void addMetrics(String transaction, SamplerMetric metric) {
// FOR ALL STATUS
addMetric(transaction, metric.getTotal(), TAG_ALL, metric.getAllMean(), metric.getAllMinTime(),
addMetric(transaction, metric.getTotal(), metric.getSentBytes(), metric.getReceivedBytes(), TAG_ALL, metric.getAllMean(), metric.getAllMinTime(),
metric.getAllMaxTime(), allPercentiles.values(), metric::getAllPercentile);
// FOR OK STATUS
addMetric(transaction, metric.getSuccesses(), TAG_OK, metric.getOkMean(), metric.getOkMinTime(),
addMetric(transaction, metric.getSuccesses(), null, null, TAG_OK, metric.getOkMean(), metric.getOkMinTime(),
metric.getOkMaxTime(), okPercentiles.values(), metric::getOkPercentile);
// FOR KO STATUS
addMetric(transaction, metric.getFailures(), TAG_KO, metric.getKoMean(), metric.getKoMinTime(),
addMetric(transaction, metric.getFailures(), null, null, TAG_KO, metric.getKoMean(), metric.getKoMinTime(),
metric.getKoMaxTime(), koPercentiles.values(), metric::getKoPercentile);
metric.getErrors().forEach((error, count) -> addErrorMetric(transaction, error.getResponseCode(),
@ -209,10 +211,11 @@ public class InfluxdbBackendListenerClient extends AbstractBackendListenerClient
}
private void addMetric(String transaction, int count,
Long sentBytes, Long receivedBytes,
String statut, double mean, double minTime, double maxTime,
Collection<Float> pcts, PercentileProvider percentileProvider) {
if (count > 0) {
StringBuilder tag = new StringBuilder(70);
StringBuilder tag = new StringBuilder(95);
tag.append(TAG_APPLICATION).append(application);
tag.append(TAG_STATUS).append(statut);
tag.append(TAG_TRANSACTION).append(transaction);
@ -229,6 +232,12 @@ public class InfluxdbBackendListenerClient extends AbstractBackendListenerClient
if (!Double.isNaN(maxTime)) {
field.append(',').append(METRIC_MAX).append(maxTime);
}
if(sentBytes != null) {
field.append(',').append(METRIC_SENT_BYTES).append(sentBytes);
}
if(receivedBytes != null) {
field.append(',').append(METRIC_RECEIVED_BYTES).append(receivedBytes);
}
for (Float pct : pcts) {
field.append(',').append(METRIC_PCT_PREFIX).append(pct).append('=').append(
percentileProvider.getPercentileValue(pct));
@ -262,10 +271,11 @@ public class InfluxdbBackendListenerClient extends AbstractBackendListenerClient
}
field.append(',').append(METRIC_HIT).append(metric.getHits());
field.append(',').append(METRIC_SENT_BYTES).append(metric.getSentBytes());
field.append(',').append(METRIC_RECEIVED_BYTES).append(metric.getReceivedBytes());
for (Float pct : pcts) {
field.append(',').append(METRIC_PCT_PREFIX).append(pct).append('=').append(Double.toString(metric.getAllPercentile(pct)));
}
field.append(',').append(METRIC_HIT).append(metric.getHits());
influxdbMetricsManager.addMetric(measurement, tag.toString(), field.toString());
}
}

View File

@ -55,6 +55,8 @@ public class SamplerMetricFixedModeTest {
assertEquals("Before reset ok.max", DEFAULT_ELAPSED_TIME, metric.getOkMaxTime(), 0.001);
assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(), 0.001);
assertEquals("Before reset failure", 1, metric.getHits(), 0.0);
assertEquals("Before reset sent bytes", 1000, metric.getSentBytes(), 0.0);
assertEquals("Before reset received bytes", 2000, metric.getReceivedBytes(), 0.0);
// In fixed mode DescriptiveStatistics are not reset, just sliding on a
// window
@ -63,6 +65,8 @@ public class SamplerMetricFixedModeTest {
assertEquals("After reset in FIXED mode ok.max", DEFAULT_ELAPSED_TIME, metric.getOkMaxTime(), 0.001);
assertEquals("After reset in FIXED mode all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(), 0.0);
assertEquals("After reset failure", 0, metric.getHits(), 0.0);
assertEquals("After reset sent bytes", 0, metric.getSentBytes(), 0.0);
assertEquals("After reset received bytes", 0, metric.getReceivedBytes(), 0.0);
}
@Test
@ -73,6 +77,8 @@ public class SamplerMetricFixedModeTest {
assertEquals("Before reset ko.max", DEFAULT_ELAPSED_TIME, metric.getKoMaxTime(), 0.001);
assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(), 0.001);
assertEquals("Before reset failure", 1, metric.getFailures(), 0.0);
assertEquals("Before reset sent bytes", 1000, metric.getSentBytes(), 0.0);
assertEquals("Before reset received bytes", 2000, metric.getReceivedBytes(), 0.0);
// In fixed mode DescriptiveStatistics are not reset, just sliding on a
// window
@ -81,6 +87,8 @@ public class SamplerMetricFixedModeTest {
assertEquals("After reset in FIXED mode ko.max", DEFAULT_ELAPSED_TIME, metric.getKoMaxTime(), 0.0);
assertEquals("After reset in FIXED mode all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(), 0.0);
assertEquals("After reset failure", 0, metric.getFailures(), 0.001);
assertEquals("After reset sent bytes", 0, metric.getSentBytes(), 0.0);
assertEquals("After reset received bytes", 0, metric.getReceivedBytes(), 0.0);
}
@Test
@ -103,6 +111,8 @@ public class SamplerMetricFixedModeTest {
result.setErrorCount(success ? 0 : 1);
result.sampleStart();
result.setEndTime(result.getStartTime() + DEFAULT_ELAPSED_TIME);
result.setSentBytes(1000);
result.setBytes(2000L);
return result;
}

View File

@ -53,12 +53,16 @@ public class SamplerMetricTimedModeTest {
assertEquals("Before reset ok.max", DEFAULT_ELAPSED_TIME, metric.getOkMaxTime(), 0.001);
assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(), 0.001);
assertEquals("Before reset failure", 1, metric.getHits(), 0.0);
assertEquals("Before reset sent bytes", 1000, metric.getSentBytes(), 0.0);
assertEquals("Before reset received bytes", 2000, metric.getReceivedBytes(), 0.0);
metric.resetForTimeInterval();
assertEquals("After reset in TIMED mode ok.max", Double.NaN, metric.getOkMaxTime(), 0.0);
assertEquals("After reset in TIMED mode all.max", Double.NaN, metric.getAllMaxTime(), 0.0);
assertEquals("After reset failure", 0, metric.getHits(), 0.0);
assertEquals("After reset sent bytes", 0, metric.getSentBytes(), 0.0);
assertEquals("After reset received bytes", 0, metric.getReceivedBytes(), 0.0);
}
@Test
@ -69,12 +73,16 @@ public class SamplerMetricTimedModeTest {
assertEquals("Before reset ko.max", DEFAULT_ELAPSED_TIME, metric.getKoMaxTime(), 0.001);
assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(), 0.001);
assertEquals("Before reset failure", 1, metric.getFailures(), 0.0);
assertEquals("Before reset sent bytes", 1000, metric.getSentBytes(), 0.0);
assertEquals("Before reset received bytes", 2000, metric.getReceivedBytes(), 0.0);
metric.resetForTimeInterval();
assertEquals("After reset in TIMED mode ko.max", Double.NaN, metric.getKoMaxTime(), 0.0);
assertEquals("After reset in TIMED mode all.max", Double.NaN, metric.getAllMaxTime(), 0.0);
assertEquals("After reset failure", 0, metric.getFailures(), 0.001);
assertEquals("After reset sent bytes", 0, metric.getSentBytes(), 0.0);
assertEquals("After reset received bytes", 0, metric.getReceivedBytes(), 0.0);
}
private SampleResult createSampleResult(boolean success) {
@ -83,6 +91,8 @@ public class SamplerMetricTimedModeTest {
result.setSampleCount(1);
result.setErrorCount(success ? 0 : 1);
result.sampleStart();
result.setSentBytes(1000);
result.setBytes(2000L);
result.setEndTime(result.getStartTime() + DEFAULT_ELAPSED_TIME);
return result;
}

View File

@ -108,6 +108,7 @@ this behaviour, set <code>httpclient.reset_state_on_thread_group_iteration=false
<li><bug>62209</bug>InfluxBackendListenerClient: First Assertion Failure Message must be sent if error code and response code are empty or ok</li>
<li><bug>62269</bug>Bug 62269 - View Results Tree : Response and Request Tabs should contains Header and Body tabs. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
<li><bug>62270</bug>View Results Tree : Allow searching in Request headers, Response Headers, and Request body. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
<li><bug>62276</bug>InfluxDBBackendListenerClient / GraphiteBackendListenerClient : Add sent and received bytes to metrics. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
</ul>
<h3>Timers, Assertions, Config, Pre- &amp; Post-Processors</h3>

View File

@ -106,6 +106,10 @@ In this document we will present the configuration setup to graph and historize
<dd>Percentile computed for failed responses of sampler name. There will be one metric for each calculated value.</dd>
<dt><code>&lt;rootMetricsPrefix&gt;&lt;samplerName&gt;.a.count</code></dt>
<dd>Number of responses for sampler name (sum of ok.count and ko.count)</dd>
<dt><code>&lt;rootMetricsPrefix&gt;&lt;samplerName&gt;.sb.bytes</code></dt>
<dd>Sent Bytes</dd>
<dt><code>&lt;rootMetricsPrefix&gt;&lt;samplerName&gt;.rb.bytes</code></dt>
<dd>Received Bytes</dd>
<dt><code>&lt;rootMetricsPrefix&gt;&lt;samplerName&gt;.a.min</code></dt>
<dd>Min response time for responses of sampler name (min of ok.count and ko.count)</dd>
<dt><code>&lt;rootMetricsPrefix&gt;&lt;samplerName&gt;.a.max</code></dt>