Search in sources :

Example 41 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)

Example 42 with Histogram

use of com.codahale.metrics.Histogram in project sling by apache.

the class MetricWebConsolePlugin method addHistogramDetails.

private void addHistogramDetails(PrintWriter pw, SortedMap<String, Histogram> histograms) {
    if (histograms.isEmpty()) {
        return;
    }
    pw.println("<br>");
    pw.println("<div class='table'>");
    pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Histograms</div>");
    pw.println("<table class='nicetable' id='data-histograms'>");
    pw.println("<thead>");
    pw.println("<tr>");
    pw.println("<th class='header'>Name</th>");
    pw.println("<th class='header'>Count</th>");
    pw.println("<th class='header'>50%</th>");
    pw.println("<th class='header'>Min</th>");
    pw.println("<th class='header'>Max</th>");
    pw.println("<th class='header'>Mean</th>");
    pw.println("<th class='header'>StdDev</th>");
    pw.println("<th class='header'>75%</th>");
    pw.println("<th class='header'>95%</th>");
    pw.println("<th class='header'>98%</th>");
    pw.println("<th class='header'>99%</th>");
    pw.println("<th class='header'>999%</th>");
    pw.println("<th>Duration Unit</th>");
    pw.println("</tr>");
    pw.println("</thead>");
    pw.println("<tbody>");
    String rowClass = "odd";
    for (Map.Entry<String, Histogram> e : histograms.entrySet()) {
        Histogram h = e.getValue();
        Snapshot s = h.getSnapshot();
        String name = e.getKey();
        double durationFactor = 1.0 / timeUnit.durationFor(name).toNanos(1);
        String durationUnit = timeUnit.durationFor(name).toString().toLowerCase(Locale.US);
        pw.printf("<tr class='%s ui-state-default'>%n", rowClass);
        pw.printf("<td>%s</td>", name);
        pw.printf("<td>%d</td>", h.getCount());
        pw.printf("<td>%f</td>", s.getMedian() * durationFactor);
        pw.printf("<td>%f</td>", s.getMin() * durationFactor);
        pw.printf("<td>%f</td>", s.getMax() * durationFactor);
        pw.printf("<td>%f</td>", s.getMean() * durationFactor);
        pw.printf("<td>%f</td>", s.getStdDev() * durationFactor);
        pw.printf("<td>%f</td>", s.get75thPercentile() * durationFactor);
        pw.printf("<td>%f</td>", s.get95thPercentile() * durationFactor);
        pw.printf("<td>%f</td>", s.get98thPercentile() * durationFactor);
        pw.printf("<td>%f</td>", s.get99thPercentile() * durationFactor);
        pw.printf("<td>%f</td>", s.get999thPercentile() * durationFactor);
        pw.printf("<td>%s</td>", durationUnit);
        pw.println("</tr>");
        rowClass = "odd".equals(rowClass) ? "even" : "odd";
    }
    pw.println("</tbody>");
    pw.println("</table>");
    pw.println("</div>");
}
Also used : Snapshot(com.codahale.metrics.Snapshot) Histogram(com.codahale.metrics.Histogram) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap)

Example 43 with Histogram

use of com.codahale.metrics.Histogram in project sling by apache.

the class MetricWrapperTest 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(1, histoStats.getCount());
    assertEquals(100, histo.getSnapshot().getMax());
    assertSame(histo, histoStats.adaptTo(Histogram.class));
}
Also used : Histogram(com.codahale.metrics.Histogram) Test(org.junit.Test)

Example 44 with Histogram

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

the class MetricsModuleTest method serializesHistograms.

@Test
public void serializesHistograms() throws Exception {
    final Histogram histogram = mock(Histogram.class);
    when(histogram.getCount()).thenReturn(1L);
    final Snapshot snapshot = mock(Snapshot.class);
    when(snapshot.getMax()).thenReturn(2L);
    when(snapshot.getMean()).thenReturn(3.0);
    when(snapshot.getMin()).thenReturn(4L);
    when(snapshot.getStdDev()).thenReturn(5.0);
    when(snapshot.getMedian()).thenReturn(6.0);
    when(snapshot.get75thPercentile()).thenReturn(7.0);
    when(snapshot.get95thPercentile()).thenReturn(8.0);
    when(snapshot.get98thPercentile()).thenReturn(9.0);
    when(snapshot.get99thPercentile()).thenReturn(10.0);
    when(snapshot.get999thPercentile()).thenReturn(11.0);
    when(snapshot.getValues()).thenReturn(new long[] { 1, 2, 3 });
    when(histogram.getSnapshot()).thenReturn(snapshot);
    assertThat(mapper.writeValueAsString(histogram)).isEqualTo("{" + "\"count\":1," + "\"max\":2," + "\"mean\":3.0," + "\"min\":4," + "\"p50\":6.0," + "\"p75\":7.0," + "\"p95\":8.0," + "\"p98\":9.0," + "\"p99\":10.0," + "\"p999\":11.0," + "\"stddev\":5.0}");
    final ObjectMapper fullMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, true, MetricFilter.ALL));
    assertThat(fullMapper.writeValueAsString(histogram)).isEqualTo("{" + "\"count\":1," + "\"max\":2," + "\"mean\":3.0," + "\"min\":4," + "\"p50\":6.0," + "\"p75\":7.0," + "\"p95\":8.0," + "\"p98\":9.0," + "\"p99\":10.0," + "\"p999\":11.0," + "\"values\":[1,2,3]," + "\"stddev\":5.0}");
}
Also used : Snapshot(com.codahale.metrics.Snapshot) Histogram(com.codahale.metrics.Histogram) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

Histogram (com.codahale.metrics.Histogram)44 Test (org.junit.Test)21 Timer (com.codahale.metrics.Timer)17 Meter (com.codahale.metrics.Meter)13 Counter (com.codahale.metrics.Counter)12 Snapshot (com.codahale.metrics.Snapshot)11 MetricRegistry (com.codahale.metrics.MetricRegistry)8 Gauge (com.codahale.metrics.Gauge)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 ConsoleReporter (com.codahale.metrics.ConsoleReporter)2 MetricFilter (com.codahale.metrics.MetricFilter)2