Search in sources :

Example 61 with Histogram

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

the class DropwizardMetricServices method submitHistogram.

private void submitHistogram(String name, double value) {
    long longValue = (long) value;
    Histogram metric = register(name, new HistogramMetricRegistrar());
    metric.update(longValue);
}
Also used : Histogram(com.codahale.metrics.Histogram)

Example 62 with Histogram

use of com.codahale.metrics.Histogram in project jackrabbit-oak by apache.

the class CompositeStatsTest method histogram.

@Test
public void histogram() throws Exception {
    Histogram histo = registry.histogram("test");
    CompositeStats histoStats = new CompositeStats(new AtomicLong(), histo);
    histoStats.update(100);
    assertEquals(1, histo.getCount());
    assertEquals(100, histo.getSnapshot().getMax());
    assertFalse(histoStats.isMeter());
    assertFalse(histoStats.isTimer());
    assertFalse(histoStats.isCounter());
    assertTrue(histoStats.isHistogram());
    assertNotNull(histoStats.getHistogram());
}
Also used : Histogram(com.codahale.metrics.Histogram) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.Test)

Example 63 with Histogram

use of com.codahale.metrics.Histogram in project jackrabbit-oak by apache.

the class MetricImplTest method histogram.

@Test
public void histogram() throws Exception {
    Histogram histo = registry.histogram("test");
    HistogramImpl histoStats = new HistogramImpl(histo);
    histoStats.update(100);
    assertEquals(1, histo.getCount());
    assertEquals(100, histo.getSnapshot().getMax());
}
Also used : Histogram(com.codahale.metrics.Histogram) Test(org.junit.Test)

Example 64 with Histogram

use of com.codahale.metrics.Histogram in project lucene-solr by apache.

the class MetricUtils method convertMetric.

/**
   * Convert a single instance of metric into a map or flattened object.
   * @param n metric name
   * @param metric metric instance
   * @param propertyFilter limit what properties of a metric are returned
   * @param skipHistograms discard any {@link Histogram}-s and histogram parts of {@link Timer}-s.
   * @param skipAggregateValues discard internal values of {@link AggregateMetric}-s.
   * @param compact use compact representation for counters and gauges.
   * @param simple use simplified representation for complex metrics - instead of a (name, map)
   *             only the selected (name "." key, value) pairs will be produced.
   * @param consumer consumer that accepts produced objects
   */
static void convertMetric(String n, Metric metric, PropertyFilter propertyFilter, boolean skipHistograms, boolean skipAggregateValues, boolean compact, boolean simple, BiConsumer<String, Object> consumer) {
    if (metric instanceof Counter) {
        Counter counter = (Counter) metric;
        convertCounter(n, counter, propertyFilter, compact, consumer);
    } else if (metric instanceof Gauge) {
        Gauge gauge = (Gauge) metric;
        try {
            convertGauge(n, gauge, propertyFilter, simple, compact, consumer);
        } catch (InternalError ie) {
            if (n.startsWith("memory.") && ie.getMessage().contains("Memory Pool not found")) {
                LOG.warn("Error converting gauge '" + n + "', possible JDK bug: SOLR-10362", ie);
                consumer.accept(n, null);
            } else {
                throw ie;
            }
        }
    } else if (metric instanceof Meter) {
        Meter meter = (Meter) metric;
        convertMeter(n, meter, propertyFilter, simple, consumer);
    } else if (metric instanceof Timer) {
        Timer timer = (Timer) metric;
        convertTimer(n, timer, propertyFilter, skipHistograms, simple, consumer);
    } else if (metric instanceof Histogram) {
        if (!skipHistograms) {
            Histogram histogram = (Histogram) metric;
            convertHistogram(n, histogram, propertyFilter, simple, consumer);
        }
    } else if (metric instanceof AggregateMetric) {
        convertAggregateMetric(n, (AggregateMetric) metric, propertyFilter, skipAggregateValues, simple, consumer);
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Meter(com.codahale.metrics.Meter) AggregateMetric(org.apache.solr.metrics.AggregateMetric) Gauge(com.codahale.metrics.Gauge)

Example 65 with Histogram

use of com.codahale.metrics.Histogram in project ddf by codice.

the class SourceMetricsImpl method updateMetric.

public void updateMetric(String sourceId, String name, int incrementAmount) {
    LOGGER.debug("sourceId = {},   name = {}", sourceId, name);
    if (StringUtils.isBlank(sourceId) || StringUtils.isBlank(name)) {
        return;
    }
    String mapKey = sourceId + "." + name;
    SourceMetric sourceMetric = metrics.get(mapKey);
    if (sourceMetric == null) {
        LOGGER.debug("sourceMetric is null for {} - creating metric now", mapKey);
        // Loop through list of all sources until find the sourceId whose metric is being
        // updated
        boolean created = createMetric(catalogProviders, sourceId);
        if (!created) {
            createMetric(federatedSources, sourceId);
        }
        sourceMetric = metrics.get(mapKey);
    }
    // If this metric already exists, then just update its MBean
    if (sourceMetric != null) {
        LOGGER.debug("CASE 1: Metric already exists for {}", mapKey);
        if (sourceMetric.isHistogram()) {
            Histogram metric = (Histogram) sourceMetric.getMetric();
            LOGGER.debug("Updating histogram metric {} by amount of {}", name, incrementAmount);
            metric.update(incrementAmount);
        } else {
            Meter metric = (Meter) sourceMetric.getMetric();
            LOGGER.debug("Updating metric {} by amount of {}", name, incrementAmount);
            metric.mark(incrementAmount);
        }
        return;
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter)

Aggregations

Histogram (com.codahale.metrics.Histogram)97 Test (org.junit.Test)39 Timer (com.codahale.metrics.Timer)34 Counter (com.codahale.metrics.Counter)30 Meter (com.codahale.metrics.Meter)29 Gauge (com.codahale.metrics.Gauge)17 Snapshot (com.codahale.metrics.Snapshot)12 Map (java.util.Map)11 Test (org.testng.annotations.Test)11 MetricRegistry (com.codahale.metrics.MetricRegistry)9 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 Metric (com.codahale.metrics.Metric)6 Reservoir (com.codahale.metrics.Reservoir)6 ZonedDateTime (java.time.ZonedDateTime)6 Properties (java.util.Properties)6 SortedMap (java.util.SortedMap)6 DateTime (org.joda.time.DateTime)6 UniformReservoir (com.codahale.metrics.UniformReservoir)5