Search in sources :

Example 6 with Histogram

use of com.codahale.metrics.Histogram in project airpal by airbnb.

the class LocalUsageStore method markUsage.

@Override
public void markUsage(Table table) {
    Histogram window = usageMap.get(table);
    if (window == null) {
        final SlidingTimeWindowReservoir reservoir = new SlidingTimeWindowReservoir(usageTrackTime.getQuantity(), usageTrackTime.getUnit());
        window = new Histogram(reservoir);
        usageMap.put(table, window);
    }
    window.update(1);
}
Also used : SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) Histogram(com.codahale.metrics.Histogram)

Example 7 with Histogram

use of com.codahale.metrics.Histogram in project spring-boot by spring-projects.

the class DropwizardMetricServicesTests method setCustomReservoirTimer.

@Test
public void setCustomReservoirTimer() {
    given(this.reservoirFactory.getReservoir(anyString())).willReturn(new UniformReservoir());
    this.writer.submit("timer.foo", 200);
    this.writer.submit("timer.foo", 300);
    assertThat(this.registry.timer("timer.foo").getCount()).isEqualTo(2);
    Timer timer = (Timer) this.registry.getMetrics().get("timer.foo");
    Histogram histogram = (Histogram) ReflectionTestUtils.getField(timer, "histogram");
    assertThat(ReflectionTestUtils.getField(histogram, "reservoir").getClass().equals(UniformReservoir.class)).isTrue();
}
Also used : Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) UniformReservoir(com.codahale.metrics.UniformReservoir) Test(org.junit.Test)

Example 8 with Histogram

use of com.codahale.metrics.Histogram 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) {
                    Snapshot snapshot1 = histogram.getSnapshot();
                    snapshot.set_mean(snapshot1.getMean());
                    snapshot.set_p50(snapshot1.getMedian());
                    snapshot.set_p75(snapshot1.get75thPercentile());
                    snapshot.set_p95(snapshot1.get95thPercentile());
                    snapshot.set_p98(snapshot1.get98thPercentile());
                    snapshot.set_p99(snapshot1.get99thPercentile());
                    snapshot.set_p999(snapshot1.get999thPercentile());
                    snapshot.set_stddev(snapshot1.getStdDev());
                    snapshot.set_min(snapshot1.getMin());
                    snapshot.set_max(snapshot1.getMax());
                    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)

Example 9 with Histogram

use of com.codahale.metrics.Histogram in project torodb by torodb.

the class ToroMetricRegistry method histogram.

/**
   *
   * @param name
   * @param resetOnSnapshot This is usually true if you're using snapshots as a means of defining
   *                        the window in which you want to calculate, say, the 99.9th percentile
   * @return
   */
public Histogram histogram(MetricName name, boolean resetOnSnapshot) {
    Reservoir reservoir;
    if (resetOnSnapshot) {
        reservoir = new HdrHistogramResetOnSnapshotReservoir();
    } else {
        reservoir = new HdrHistogramReservoir();
    }
    Histogram histogram = register(name, new Histogram(reservoir));
    return histogram;
}
Also used : HdrHistogramReservoir(org.mpierce.metrics.reservoir.hdrhistogram.HdrHistogramReservoir) Histogram(com.codahale.metrics.Histogram) HdrHistogramResetOnSnapshotReservoir(org.mpierce.metrics.reservoir.hdrhistogram.HdrHistogramResetOnSnapshotReservoir) HdrHistogramReservoir(org.mpierce.metrics.reservoir.hdrhistogram.HdrHistogramReservoir) HdrHistogramResetOnSnapshotReservoir(org.mpierce.metrics.reservoir.hdrhistogram.HdrHistogramResetOnSnapshotReservoir) Reservoir(com.codahale.metrics.Reservoir)

Example 10 with Histogram

use of com.codahale.metrics.Histogram in project HikariCP by brettwooldridge.

the class TestMetrics method testMetricUsage.

@Test
public void testMetricUsage() throws SQLException {
    assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS));
    MetricRegistry metricRegistry = new MetricRegistry();
    HikariConfig config = newHikariConfig();
    config.setMinimumIdle(1);
    config.setMaximumPoolSize(1);
    config.setMetricRegistry(metricRegistry);
    config.setInitializationFailTimeout(0);
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    try (HikariDataSource ds = new HikariDataSource(config)) {
        try (Connection connection = ds.getConnection()) {
            UtilityElf.quietlySleep(250L);
        }
        Histogram histo = metricRegistry.getHistograms(new MetricFilter() {

            /** {@inheritDoc} */
            @Override
            public boolean matches(String name, Metric metric) {
                return name.equals(MetricRegistry.name("testMetricUsage", "pool", "Usage"));
            }
        }).values().iterator().next();
        assertEquals(1, histo.getCount());
        double seventyFifth = histo.getSnapshot().get75thPercentile();
        assertTrue("Seventy-fith percentile less than 250ms: " + seventyFifth, seventyFifth >= 250.0);
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) TestElf.newHikariDataSource(com.zaxxer.hikari.pool.TestElf.newHikariDataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) MetricFilter(com.codahale.metrics.MetricFilter) MetricRegistry(com.codahale.metrics.MetricRegistry) Connection(java.sql.Connection) Metric(com.codahale.metrics.Metric) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Aggregations

Histogram (com.codahale.metrics.Histogram)40 Test (org.junit.Test)18 Timer (com.codahale.metrics.Timer)17 Meter (com.codahale.metrics.Meter)13 Counter (com.codahale.metrics.Counter)11 Snapshot (com.codahale.metrics.Snapshot)8 Gauge (com.codahale.metrics.Gauge)7 MetricRegistry (com.codahale.metrics.MetricRegistry)7 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)5 ZonedDateTime (java.time.ZonedDateTime)5 Map (java.util.Map)5 DateTime (org.joda.time.DateTime)5 Metric (com.codahale.metrics.Metric)4 UniformReservoir (com.codahale.metrics.UniformReservoir)3 SortedMap (java.util.SortedMap)3 AggregateMetric (org.apache.solr.metrics.AggregateMetric)3 MetricSnapshot (backtype.storm.generated.MetricSnapshot)2 JAverageSnapshot (com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot)2 MetricFilter (com.codahale.metrics.MetricFilter)2 Reservoir (com.codahale.metrics.Reservoir)2