protected SamplerMetric getSamplerMetricInfluxdb(String sampleLabel) { SamplerMetric samplerMetric = metricsPerSampler.get(sampleLabel); if (samplerMetric == null) { samplerMetric = new SamplerMetric(); SamplerMetric oldValue = metricsPerSampler.putIfAbsent(sampleLabel, samplerMetric); if (oldValue != null) { samplerMetric = oldValue; } } return samplerMetric; }
/** * Add request metrics to metrics manager. * * @param metric * {@link SamplerMetric} */ private void addMetrics(String transaction, SamplerMetric metric) { // FOR ALL STATUS 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(), null, null, TAG_OK, metric.getOkMean(), metric.getOkMinTime(), metric.getOkMaxTime(), okPercentiles.values(), metric::getOkPercentile); // FOR KO STATUS 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(), error.getResponseMessage(), count)); }
private void addCumulatedMetrics(SamplerMetric metric) { int total = metric.getTotal(); if (total > 0) { StringBuilder tag = new StringBuilder(70); StringBuilder field = new StringBuilder(100); Collection<Float> pcts = allPercentiles.values(); tag.append(TAG_APPLICATION).append(application); tag.append(TAG_TRANSACTION).append(CUMULATED_METRICS); tag.append(TAG_STATUS).append(CUMULATED_METRICS); tag.append(userTag); field.append(METRIC_COUNT).append(total); field.append(',').append(METRIC_COUNT_ERROR).append(metric.getFailures()); if (!Double.isNaN(metric.getOkMean())) { field.append(',').append(METRIC_AVG).append(Double.toString(metric.getOkMean())); } if (!Double.isNaN(metric.getOkMinTime())) { field.append(',').append(METRIC_MIN).append(Double.toString(metric.getOkMinTime())); } if (!Double.isNaN(metric.getOkMaxTime())) { field.append(',').append(METRIC_MAX).append(Double.toString(metric.getOkMaxTime())); } 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))); } influxdbMetricsManager.addMetric(measurement, tag.toString(), field.toString()); } }
if(metric.getTotal() > 0) { graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_OK_COUNT, Integer.toString(metric.getSuccesses())); graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_KO_COUNT, Integer.toString(metric.getFailures())); graphiteMetricsManager.addMetric(timestampInSeconds, contextName, 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, Double.toString(metric.getOkMinTime())); graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_OK_MAX_RESPONSE_TIME, Double.toString(metric.getOkMaxTime())); graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_OK_AVG_RESPONSE_TIME, Double.toString(metric.getOkMean())); for (Map.Entry<String, Float> entry : okPercentiles.entrySet()) { graphiteMetricsManager.addMetric(timestampInSeconds, contextName, entry.getKey(), Double.toString(metric.getOkPercentile(entry.getValue().floatValue()))); if(metric.getFailures()>0) {
/** * Add a {@link SampleResult} to be used in the statistics * @param result {@link SampleResult} to be used */ public synchronized void add(SampleResult result) { if(result.isSuccessful()) { successes+=result.getSampleCount()-result.getErrorCount(); } else { failures+=result.getErrorCount(); ErrorMetric error = new ErrorMetric(result); errors.put(error, errors.getOrDefault(error, 0) + result.getErrorCount() ); } long time = result.getTime(); allResponsesStats.addValue(time); pctResponseStats.addValue(time); if(result.isSuccessful()) { // Should we also compute KO , all response time ? // only take successful requests for time computing okResponsesStats.addValue(time); }else { koResponsesStats.addValue(time); } addHits(result); addNetworkData(result); }
@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.add(sampleResult); } } }
/** * Compute hits from res * @param res {@link SampleResult} */ private void addHits(SampleResult res) { SampleResult[] subResults = res.getSubResults(); if (!TransactionController.isFromTransactionController(res)) { hits += 1; } for (SampleResult subResult : subResults) { addHits(subResult); } }
@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); } } SamplerMetric cumulatedMetrics = getSamplerMetric(CUMULATED_METRICS); cumulatedMetrics.add(sampleResult); } } }
/** * @param sampleLabel Name of sample used as key * @return {@link SamplerMetric} */ protected final SamplerMetric getSamplerMetric(String sampleLabel) { SamplerMetric samplerMetric = metricsPerSampler.get(sampleLabel); if(samplerMetric == null) { samplerMetric = new SamplerMetric(); SamplerMetric oldValue = metricsPerSampler.putIfAbsent(sampleLabel, samplerMetric); if(oldValue != null ){ samplerMetric = oldValue; } } return samplerMetric; }