Search in sources :

Example 16 with Snapshot

use of com.codahale.metrics.Snapshot in project gerrit by GerritCodeReview.

the class MetricJson method init.

private void init(Metric metric, ImmutableMap<String, String> atts) {
    if (metric instanceof BucketedMetric) {
        BucketedMetric m = (BucketedMetric) metric;
        if (m.getTotal() != null) {
            init(m.getTotal(), atts);
        }
        Field<?>[] fieldList = m.getFields();
        fields = new ArrayList<>(fieldList.length);
        for (Field<?> f : fieldList) {
            fields.add(new FieldJson(f));
        }
        buckets = makeBuckets(fieldList, m.getCells(), atts);
    } else if (metric instanceof Counter) {
        Counter c = (Counter) metric;
        count = c.getCount();
    } else if (metric instanceof Gauge) {
        Gauge<?> g = (Gauge<?>) metric;
        value = g.getValue();
    } else if (metric instanceof Meter) {
        Meter m = (Meter) metric;
        count = m.getCount();
        rate_1m = m.getOneMinuteRate();
        rate_5m = m.getFiveMinuteRate();
        rate_15m = m.getFifteenMinuteRate();
    } else if (metric instanceof Timer) {
        Timer m = (Timer) metric;
        Snapshot s = m.getSnapshot();
        count = m.getCount();
        rate_1m = m.getOneMinuteRate();
        rate_5m = m.getFiveMinuteRate();
        rate_15m = m.getFifteenMinuteRate();
        double div = Description.getTimeUnit(atts.get(Description.UNIT)).toNanos(1);
        p50 = s.getMedian() / div;
        p75 = s.get75thPercentile() / div;
        p95 = s.get95thPercentile() / div;
        p98 = s.get98thPercentile() / div;
        p99 = s.get99thPercentile() / div;
        p99_9 = s.get999thPercentile() / div;
        min = s.getMin() / div;
        max = s.getMax() / div;
        std_dev = s.getStdDev() / div;
    } else if (metric instanceof Histogram) {
        Histogram m = (Histogram) metric;
        Snapshot s = m.getSnapshot();
        count = m.getCount();
        p50 = s.getMedian();
        p75 = s.get75thPercentile();
        p95 = s.get95thPercentile();
        p98 = s.get98thPercentile();
        p99 = s.get99thPercentile();
        p99_9 = s.get999thPercentile();
        min = (double) s.getMin();
        avg = s.getMean();
        max = (double) s.getMax();
        sum = s.getMean() * m.getCount();
        std_dev = s.getStdDev();
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) Gauge(com.codahale.metrics.Gauge) Field(com.google.gerrit.metrics.Field) Snapshot(com.codahale.metrics.Snapshot) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer)

Example 17 with Snapshot

use of com.codahale.metrics.Snapshot in project hbase by apache.

the class TestPerformanceEvaluation method testZipfian.

@Test
public void testZipfian() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    TestOptions opts = new PerformanceEvaluation.TestOptions();
    opts.setValueZipf(true);
    final int valueSize = 1024;
    opts.setValueSize(valueSize);
    RandomReadTest rrt = new RandomReadTest(null, opts, null);
    Constructor<?> ctor = Histogram.class.getDeclaredConstructor(com.codahale.metrics.Reservoir.class);
    ctor.setAccessible(true);
    Histogram histogram = (Histogram) ctor.newInstance(new UniformReservoir(1024 * 500));
    for (int i = 0; i < 100; i++) {
        histogram.update(rrt.getValueLength(null));
    }
    Snapshot snapshot = histogram.getSnapshot();
    double stddev = snapshot.getStdDev();
    assertTrue(stddev != 0 && stddev != 1.0);
    assertTrue(snapshot.getStdDev() != 0);
    double median = snapshot.getMedian();
    assertTrue(median != 0 && median != 1 && median != valueSize);
}
Also used : RandomReadTest(org.apache.hadoop.hbase.PerformanceEvaluation.RandomReadTest) Snapshot(com.codahale.metrics.Snapshot) Histogram(com.codahale.metrics.Histogram) TestOptions(org.apache.hadoop.hbase.PerformanceEvaluation.TestOptions) UniformReservoir(com.codahale.metrics.UniformReservoir) RandomReadTest(org.apache.hadoop.hbase.PerformanceEvaluation.RandomReadTest) Test(org.junit.Test)

Example 18 with Snapshot

use of com.codahale.metrics.Snapshot in project chassis by Kixeye.

the class MetricsCloudWatchReporter method addHistograms.

private void addHistograms(SortedMap<String, Histogram> histograms, LinkedList<PutMetricDataRequest> requests, Date timestamp) {
    logger.debug("Adding Histograms...");
    for (String name : histograms.keySet()) {
        Histogram histogram = histograms.get(name);
        Snapshot snapshot = histogram.getSnapshot();
        checkAndAddDatum(MetricFilter.Stat.COUNT, name, histogram.getCount(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.MIN, name, snapshot.getMin(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.MAX, name, snapshot.getMax(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.MEAN, name, snapshot.getMean(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.STDDEV, name, snapshot.getStdDev(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_75, name, snapshot.get75thPercentile(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_95, name, snapshot.get95thPercentile(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_98, name, snapshot.get98thPercentile(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_99, name, snapshot.get99thPercentile(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_999, name, snapshot.get999thPercentile(), requests, timestamp);
    }
}
Also used : Snapshot(com.codahale.metrics.Snapshot) Histogram(com.codahale.metrics.Histogram)

Example 19 with Snapshot

use of com.codahale.metrics.Snapshot in project newts by OpenNMS.

the class NewtsReporter method reportTimer.

private void reportTimer(List<Sample> samples, Timestamp timestamp, String name, Timer timer) {
    final Snapshot snapshot = timer.getSnapshot();
    Map<String, String> rateAttr = Maps.newHashMap();
    rateAttr.put("rate_unit", getRateUnit());
    Map<String, String> durationAttr = Maps.newHashMap();
    durationAttr.put("duration_unit", getDurationUnit());
    reportC(samples, timestamp, name, "count", timer.getCount());
    reportG(samples, timestamp, name, "max", convertDuration(snapshot.getMax()), durationAttr);
    reportG(samples, timestamp, name, "mean", convertDuration(snapshot.getMean()), durationAttr);
    reportG(samples, timestamp, name, "min", convertDuration(snapshot.getMin()), durationAttr);
    reportG(samples, timestamp, name, "stddev", convertDuration(snapshot.getStdDev()), durationAttr);
    reportG(samples, timestamp, name, "p50", convertDuration(snapshot.getMedian()), durationAttr);
    reportG(samples, timestamp, name, "p75", convertDuration(snapshot.get75thPercentile()), durationAttr);
    reportG(samples, timestamp, name, "p95", convertDuration(snapshot.get95thPercentile()), durationAttr);
    reportG(samples, timestamp, name, "p98", convertDuration(snapshot.get98thPercentile()), durationAttr);
    reportG(samples, timestamp, name, "p99", convertDuration(snapshot.get99thPercentile()), durationAttr);
    reportG(samples, timestamp, name, "p999", convertDuration(snapshot.get999thPercentile()), durationAttr);
    reportG(samples, timestamp, name, "mean_rate", convertRate(timer.getMeanRate()), rateAttr);
    reportG(samples, timestamp, name, "m1_rate", convertRate(timer.getOneMinuteRate()), rateAttr);
    reportG(samples, timestamp, name, "m5_rate", convertRate(timer.getFiveMinuteRate()), rateAttr);
    reportG(samples, timestamp, name, "m15_rate", convertRate(timer.getFifteenMinuteRate()), rateAttr);
}
Also used : Snapshot(com.codahale.metrics.Snapshot)

Example 20 with Snapshot

use of com.codahale.metrics.Snapshot in project jstorm by alibaba.

the class TopologyMetricContext method adjustMetrics.

private void adjustMetrics(Map<String, Map<Integer, MetricSnapshot>> metrics, Map<String, Integer> metaCounters, Map<String, Map<Integer, Histogram>> histograms) {
    for (Map.Entry<String, Map<Integer, MetricSnapshot>> metricEntry : metrics.entrySet()) {
        String meta = metricEntry.getKey();
        MetricType metricType = MetricUtils.metricType(meta);
        MetaType metaType = MetricUtils.metaType(meta);
        Map<Integer, MetricSnapshot> winData = metricEntry.getValue();
        if (metricType == MetricType.HISTOGRAM) {
            for (Map.Entry<Integer, MetricSnapshot> dataEntry : winData.entrySet()) {
                MetricSnapshot snapshot = dataEntry.getValue();
                Integer cnt = metaCounters.get(meta);
                Histogram histogram = histograms.get(meta).get(dataEntry.getKey());
                if (cnt != null && cnt > 1) {
                    int denominator = 1;
                    if (!MetricUtils.metricAccurateCal)
                        denominator = cnt;
                    Snapshot snapshot1 = histogram.getSnapshot();
                    snapshot.set_mean(snapshot1.getMean() / denominator);
                    snapshot.set_p50(snapshot1.getMedian() / denominator);
                    snapshot.set_p75(snapshot1.get75thPercentile() / denominator);
                    snapshot.set_p95(snapshot1.get95thPercentile() / denominator);
                    snapshot.set_p98(snapshot1.get98thPercentile() / denominator);
                    snapshot.set_p99(snapshot1.get99thPercentile() / denominator);
                    snapshot.set_p999(snapshot1.get999thPercentile() / denominator);
                    snapshot.set_stddev(snapshot1.getStdDev() / denominator);
                    snapshot.set_min(snapshot1.getMin() / denominator);
                    snapshot.set_max(snapshot1.getMax() / denominator);
                    if (MetricUtils.metricAccurateCal && metaType == MetaType.TOPOLOGY) {
                        snapshot.set_points(MetricUtils.longs2bytes(snapshot1.getValues()));
                    }
                }
                if (metaType != MetaType.TOPOLOGY || !MetricUtils.metricAccurateCal) {
                    snapshot.set_points(new byte[0]);
                }
            }
        }
    }
}
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) ConcurrentMap(java.util.concurrent.ConcurrentMap) MetricSnapshot(backtype.storm.generated.MetricSnapshot)

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