Search in sources :

Example 56 with Counter

use of com.codahale.metrics.Counter 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 57 with Counter

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

the class MetricWebConsolePlugin method addCounterDetails.

private void addCounterDetails(PrintWriter pw, SortedMap<String, Counter> counters) {
    if (counters.isEmpty()) {
        return;
    }
    pw.println("<br>");
    pw.println("<div class='table'>");
    pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Counters</div>");
    pw.println("<table class='nicetable' id='data-counters'>");
    pw.println("<thead>");
    pw.println("<tr>");
    pw.println("<th class='header'>Name</th>");
    pw.println("<th class='header'>Count</th>");
    pw.println("</tr>");
    pw.println("</thead>");
    pw.println("<tbody>");
    String rowClass = "odd";
    for (Map.Entry<String, Counter> e : counters.entrySet()) {
        Counter c = e.getValue();
        String name = e.getKey();
        pw.printf("<tr class='%s ui-state-default'>%n", rowClass);
        pw.printf("<td>%s</td>", name);
        pw.printf("<td>%d</td>", c.getCount());
        pw.println("</tr>");
        rowClass = "odd".equals(rowClass) ? "even" : "odd";
    }
    pw.println("</tbody>");
    pw.println("</table>");
    pw.println("</div>");
}
Also used : Counter(com.codahale.metrics.Counter) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap)

Example 58 with Counter

use of com.codahale.metrics.Counter in project hive by apache.

the class TestCodahaleMetrics method testCount.

@Test
public void testCount() throws Exception {
    int runs = 5;
    for (int i = 0; i < runs; i++) {
        MetricsFactory.getInstance().incrementCounter("count1");
        Counter counter = metricRegistry.getCounters().get("count1");
        Assert.assertEquals(i + 1, counter.getCount());
    }
}
Also used : Counter(com.codahale.metrics.Counter) Test(org.junit.Test)

Example 59 with Counter

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

the class GraphiteReporterTest method disabledMetricsAttribute.

@Test
public void disabledMetricsAttribute() throws Exception {
    final Meter meter = mock(Meter.class);
    when(meter.getCount()).thenReturn(1L);
    when(meter.getOneMinuteRate()).thenReturn(2.0);
    when(meter.getFiveMinuteRate()).thenReturn(3.0);
    when(meter.getFifteenMinuteRate()).thenReturn(4.0);
    when(meter.getMeanRate()).thenReturn(5.0);
    final Counter counter = mock(Counter.class);
    when(counter.getCount()).thenReturn(11L);
    Set<MetricAttribute> disabledMetricAttributes = EnumSet.of(MetricAttribute.M15_RATE, MetricAttribute.M5_RATE);
    GraphiteReporter reporterWithdisabledMetricAttributes = GraphiteReporter.forRegistry(registry).withClock(clock).prefixedWith("prefix").convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).disabledMetricAttributes(disabledMetricAttributes).build(graphite);
    reporterWithdisabledMetricAttributes.report(map(), map("counter", counter), map(), map("meter", meter), map());
    final InOrder inOrder = inOrder(graphite);
    inOrder.verify(graphite).connect();
    inOrder.verify(graphite).send("prefix.counter.count", "11", timestamp);
    inOrder.verify(graphite).send("prefix.meter.count", "1", timestamp);
    inOrder.verify(graphite).send("prefix.meter.m1_rate", "2.00", timestamp);
    inOrder.verify(graphite).send("prefix.meter.mean_rate", "5.00", timestamp);
    inOrder.verify(graphite).flush();
    inOrder.verify(graphite).close();
    verifyNoMoreInteractions(graphite);
}
Also used : Counter(com.codahale.metrics.Counter) InOrder(org.mockito.InOrder) Meter(com.codahale.metrics.Meter) MetricAttribute(com.codahale.metrics.MetricAttribute) Test(org.junit.Test)

Example 60 with Counter

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

the class GraphiteReporterTest method reportsCounters.

@Test
public void reportsCounters() throws Exception {
    final Counter counter = mock(Counter.class);
    when(counter.getCount()).thenReturn(100L);
    reporter.report(map(), map("counter", counter), map(), map(), map());
    final InOrder inOrder = inOrder(graphite);
    inOrder.verify(graphite).connect();
    inOrder.verify(graphite).send("prefix.counter.count", "100", timestamp);
    inOrder.verify(graphite).flush();
    inOrder.verify(graphite).close();
    verifyNoMoreInteractions(graphite);
}
Also used : Counter(com.codahale.metrics.Counter) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Aggregations

Counter (com.codahale.metrics.Counter)66 Test (org.junit.Test)31 Map (java.util.Map)15 MetricRegistry (com.codahale.metrics.MetricRegistry)14 Timer (com.codahale.metrics.Timer)14 Histogram (com.codahale.metrics.Histogram)11 HashMap (java.util.HashMap)11 Gauge (com.codahale.metrics.Gauge)10 Meter (com.codahale.metrics.Meter)9 Metric (com.codahale.metrics.Metric)9 Random (java.util.Random)8 SolrInfoBean (org.apache.solr.core.SolrInfoBean)6 SortedMap (java.util.SortedMap)5 IOException (java.io.IOException)4 TreeMap (java.util.TreeMap)4 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)4 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)4 Description (com.google.gerrit.metrics.Description)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3