Search in sources :

Example 51 with Snapshot

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));
}
Also used : Snapshot(com.codahale.metrics.Snapshot)

Example 52 with Snapshot

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);
}
Also used : MetricSnapshot(backtype.storm.generated.MetricSnapshot) Snapshot(com.codahale.metrics.Snapshot) JAverageSnapshot(com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot) Histogram(com.codahale.metrics.Histogram) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JAverageSnapshot(com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot) MetricSnapshot(backtype.storm.generated.MetricSnapshot) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 53 with Snapshot

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");
    }
}
Also used : Snapshot(com.codahale.metrics.Snapshot) DecimalFormat(java.text.DecimalFormat) Map(java.util.Map)

Example 54 with Snapshot

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);
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) Snapshot(com.codahale.metrics.Snapshot) SlidingWindowReservoir(com.codahale.metrics.SlidingWindowReservoir) TestMetricGroup(org.apache.flink.metrics.util.TestMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup) Test(org.junit.jupiter.api.Test) AbstractHistogramTest(org.apache.flink.metrics.AbstractHistogramTest)

Example 55 with Snapshot

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);
        }
    };
}
Also used : Snapshot(com.codahale.metrics.Snapshot) PrintStream(java.io.PrintStream) OutputStream(java.io.OutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AtomicHistogram(org.HdrHistogram.AtomicHistogram)

Aggregations

Snapshot (com.codahale.metrics.Snapshot)57 Test (org.junit.Test)13 Histogram (com.codahale.metrics.Histogram)11 Timer (com.codahale.metrics.Timer)11 Map (java.util.Map)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 HashMap (java.util.HashMap)3 SortedMap (java.util.SortedMap)3 MetricSnapshot (backtype.storm.generated.MetricSnapshot)2 JAverageSnapshot (com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot)2 Counter (com.codahale.metrics.Counter)2 Gauge (com.codahale.metrics.Gauge)2 Meter (com.codahale.metrics.Meter)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 InOrder (org.mockito.InOrder)2 SlidingWindowReservoir (com.codahale.metrics.SlidingWindowReservoir)1 UniformReservoir (com.codahale.metrics.UniformReservoir)1 ResultSet (com.datastax.driver.core.ResultSet)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1