use of com.codahale.metrics.Snapshot in project samza by apache.
the class SamzaHistogram method updateGaugeValues.
public void updateGaugeValues(double percentile) {
Snapshot values = histogram.getSnapshot();
gauges.get(percentile).set(values.getValue(percentile / 100));
}
use of com.codahale.metrics.Snapshot in project jstorm by alibaba.
the class TopologyMetricContext method mergeHistograms.
/**
* histograms are sampled, but we just update points
*/
public void mergeHistograms(MetricInfo metricInfo, String meta, Map<Integer, MetricSnapshot> data, Map<String, Integer> metaCounters, Map<String, Map<Integer, Histogram>> histograms) {
Map<Integer, MetricSnapshot> existing = metricInfo.get_metrics().get(meta);
if (existing == null) {
metricInfo.put_to_metrics(meta, data);
Map<Integer, Histogram> histogramMap = new HashMap<>();
for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) {
Histogram histogram = MetricUtils.metricSnapshot2Histogram(dataEntry.getValue());
histogramMap.put(dataEntry.getKey(), histogram);
}
histograms.put(meta, histogramMap);
} else {
for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) {
Integer win = dataEntry.getKey();
MetricSnapshot snapshot = dataEntry.getValue();
MetricSnapshot old = existing.get(win);
if (old == null) {
existing.put(win, snapshot);
histograms.get(meta).put(win, MetricUtils.metricSnapshot2Histogram(snapshot));
} else {
if (snapshot.get_ts() >= old.get_ts()) {
old.set_ts(snapshot.get_ts());
Histogram histogram = histograms.get(meta).get(win);
Snapshot updateSnapshot = histogram.getSnapshot();
if (updateSnapshot instanceof JAverageSnapshot) {
sumMetricSnapshot(((JAverageSnapshot) updateSnapshot).getMetricSnapshot(), snapshot);
} else {
// update points
MetricUtils.updateHistogramPoints(histogram, snapshot.get_points(), snapshot.get_pointSize());
}
}
}
}
}
updateMetricCounters(meta, metaCounters);
}
use of com.codahale.metrics.Snapshot in project motan by weibocom.
the class AccessStatisticItem method logAccessStatistic.
public static void logAccessStatistic(boolean clear) {
DecimalFormat mbFormat = new DecimalFormat("#0.00");
long currentTimeMillis = System.currentTimeMillis();
ConcurrentMap<String, AccessStatisticResult> totalResults = new ConcurrentHashMap<>();
for (Map.Entry<String, AccessStatisticItem> entry : accessStatistics.entrySet()) {
AccessStatisticItem item = entry.getValue();
AccessStatisticResult result = item.getStatisticResult(currentTimeMillis, MotanConstants.STATISTIC_PEROID);
if (clear) {
item.clearStatistic(currentTimeMillis, MotanConstants.STATISTIC_PEROID);
}
String key = entry.getKey();
String[] keys = key.split(SEPARATE);
if (keys.length != 3) {
continue;
}
String application = keys[1];
String module = keys[2];
key = application + "|" + module;
AccessStatisticResult appResult = totalResults.get(key);
if (appResult == null) {
totalResults.putIfAbsent(key, new AccessStatisticResult());
appResult = totalResults.get(key);
}
appResult.totalCount += result.totalCount;
appResult.bizExceptionCount += result.bizExceptionCount;
appResult.slowCount += result.slowCount;
appResult.costTime += result.costTime;
appResult.bizTime += result.bizTime;
appResult.otherExceptionCount += result.otherExceptionCount;
Snapshot snapshot = InternalMetricsFactory.getRegistryInstance(entry.getKey()).histogram(HISTOGRAM_NAME).getSnapshot();
if (application.equals(APPLICATION_STATISTIC)) {
continue;
}
if (result.totalCount == 0) {
LoggerUtil.accessStatsLog("[motan-accessStatistic] app: " + application + " module: " + module + " item: " + keys[0] + " total_count: 0 slow_count: 0 biz_excp: 0 other_excp: 0 avg_time: 0.00ms biz_time: 0.00ms avg_tps: 0 max_tps: 0 min_tps: 0");
} else {
LoggerUtil.accessStatsLog("[motan-accessStatistic] app: {} module: {} item: {} total_count: {} slow_count: {} p75: {} p95: {} p98: {} p99: {} p999: {} biz_excp: {} other_excp: {} avg_time: {}ms biz_time: {}ms avg_tps: {} max_tps: {} min_tps: {} ", application, module, keys[0], result.totalCount, result.slowCount, mbFormat.format(snapshot.get75thPercentile()), mbFormat.format(snapshot.get95thPercentile()), mbFormat.format(snapshot.get98thPercentile()), mbFormat.format(snapshot.get99thPercentile()), mbFormat.format(snapshot.get999thPercentile()), result.bizExceptionCount, result.otherExceptionCount, mbFormat.format(result.costTime / result.totalCount), mbFormat.format(result.bizTime / result.totalCount), (result.totalCount / MotanConstants.STATISTIC_PEROID), result.maxCount, result.minCount);
}
}
if (!totalResults.isEmpty()) {
for (Map.Entry<String, AccessStatisticResult> entry : totalResults.entrySet()) {
String application = entry.getKey().split(SEPARATE)[0];
String module = entry.getKey().split(SEPARATE)[1];
AccessStatisticResult totalResult = entry.getValue();
Snapshot snapshot = InternalMetricsFactory.getRegistryInstance(entry.getKey()).histogram(HISTOGRAM_NAME).getSnapshot();
if (totalResult.totalCount > 0) {
LoggerUtil.accessStatsLog("[motan-totalAccessStatistic] app: {} module: {} total_count: {} slow_count: {} p75: {} p95: {} p98: {} p99: {} p999: {} biz_excp: {} other_excp: {} avg_time: {}ms biz_time: {}ms avg_tps: {}", application, module, totalResult.totalCount, totalResult.slowCount, mbFormat.format(snapshot.get75thPercentile()), mbFormat.format(snapshot.get95thPercentile()), mbFormat.format(snapshot.get98thPercentile()), mbFormat.format(snapshot.get99thPercentile()), mbFormat.format(snapshot.get999thPercentile()), totalResult.bizExceptionCount, totalResult.otherExceptionCount, mbFormat.format(totalResult.costTime / totalResult.totalCount), mbFormat.format(totalResult.bizTime / totalResult.totalCount), (totalResult.totalCount / MotanConstants.STATISTIC_PEROID));
} else {
LoggerUtil.accessStatsLog("[motan-totalAccessStatistic] app: " + application + " module: " + module + " total_count: 0 slow_count: 0 biz_excp: 0 other_excp: 0 avg_time: 0.00ms biz_time: 0.00ms avg_tps: 0");
}
}
} else {
LoggerUtil.accessStatsLog("[motan-totalAccessStatistic] app: " + URLParamType.application.getValue() + " module: " + URLParamType.module.getValue() + " total_count: 0 slow_count: 0 biz_excp: 0 other_excp: 0 avg_time: 0.00ms biz_time: 0.00ms avg_tps: 0");
}
}
use of com.codahale.metrics.Snapshot in project flink by apache.
the class DropwizardFlinkHistogramWrapperTest method testDropwizardHistogramWrapperReporting.
/**
* Tests that the DropwizardHistogramWrapper reports correct dropwizard snapshots to the
* ScheduledReporter.
*/
@Test
void testDropwizardHistogramWrapperReporting() throws Exception {
int size = 10;
String histogramMetricName = "histogram";
final TestingReporter testingReporter = new TestingReporter();
testingReporter.open(new MetricConfig());
DropwizardHistogramWrapper histogramWrapper = new DropwizardHistogramWrapper(new com.codahale.metrics.Histogram(new SlidingWindowReservoir(size)));
final MetricGroup metricGroup = TestMetricGroup.newBuilder().build();
testingReporter.notifyOfAddedMetric(histogramWrapper, histogramMetricName, metricGroup);
// check that the metric has been registered
assertThat(testingReporter.getMetrics()).hasSize(1);
for (int i = 0; i < size; i++) {
histogramWrapper.update(i);
}
testingReporter.report();
String fullMetricName = metricGroup.getMetricIdentifier(histogramMetricName);
Snapshot snapshot = testingReporter.getNextHistogramSnapshot(fullMetricName);
assertThat(snapshot.getMin()).isEqualTo(0);
assertThat(snapshot.getMedian()).isCloseTo((size - 1) / 2.0, offset(0.001));
assertThat(snapshot.getMax()).isEqualTo(size - 1);
assertThat(snapshot.size()).isEqualTo(size);
testingReporter.notifyOfRemovedMetric(histogramWrapper, histogramMetricName, metricGroup);
// check that the metric has been de-registered
assertThat(testingReporter.getMetrics()).hasSize(0);
}
use of com.codahale.metrics.Snapshot in project graylog2-server by Graylog2.
the class HdrHistogram method getSnapshot.
@Override
public Snapshot getSnapshot() {
final AtomicHistogram copy = hdrHistogram.copy();
return new Snapshot() {
@Override
public double getValue(double quantile) {
return copy.getValueAtPercentile(quantile * 100);
}
@Override
public long[] getValues() {
return new long[0];
}
@Override
public int size() {
return 0;
}
@Override
public long getMax() {
return copy.getMaxValue();
}
@Override
public double getMean() {
final double mean = copy.getMean();
return Double.isNaN(mean) ? 0 : mean;
}
@Override
public long getMin() {
final long minValue = copy.getMinValue();
return minValue == Long.MAX_VALUE ? 0 : minValue;
}
@Override
public double getStdDev() {
final double stdDeviation = copy.getStdDeviation();
return Double.isNaN(stdDeviation) ? 0 : stdDeviation;
}
@Override
public void dump(OutputStream output) {
final PrintStream printStream;
try {
printStream = new PrintStream(output, false, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
copy.outputPercentileDistribution(printStream, 1d);
}
};
}
Aggregations