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);
}
}
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>");
}
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());
}
}
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);
}
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);
}
Aggregations