Search in sources :

Example 1 with Reporter

use of com.codahale.metrics.Reporter in project riposte by Nike-Inc.

the class ReporterFactoryInstanceTest method test.

@Test
public void test() {
    MetricRegistry registry = new MetricRegistry();
    Reporter r = new DefaultConsoleReporterFactory().getReporter(registry);
    assertNotNull(r);
    r = new DefaultJMXReporterFactory().getReporter(registry);
    assertNotNull(r);
    r = new DefaultSLF4jReporterFactory().getReporter(registry);
    assertNotNull(r);
    r = new DefaultGraphiteReporterFactory("test", "fakeurl.com", 4242).getReporter(registry);
    assertNotNull(r);
    r = new RiposteGraphiteReporterFactory("test", "fakeurl.com", 4242).getReporter(registry);
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Reporter(com.codahale.metrics.Reporter) Test(org.junit.Test)

Example 2 with Reporter

use of com.codahale.metrics.Reporter in project riposte by Nike-Inc.

the class CodahaleMetricsEngine method startReporter.

final boolean startReporter(ReporterFactory reporterFactory) {
    boolean success = false;
    try {
        reporterFactory.startReporter();
        return true;
    } catch (UnsupportedOperationException e) {
        logger.debug("ReporterFactory {} does not expose custom startup behavior.", reporterFactory.getClass().getName());
    }
    Reporter reporter = reporterFactory.getReporter(metricsCollector.getMetricRegistry());
    if (reporter instanceof ScheduledReporter) {
        ((ScheduledReporter) reporter).start(reporterFactory.getInterval(), reporterFactory.getTimeUnit());
        return true;
    }
    // try to figure out what to do via reflection since there is no standard way to start a Reporter
    try {
        if (!reporterFactory.isScheduled() || reporterFactory.getInterval() == null) {
            // look for a start() method
            Method m = reporter.getClass().getMethod("start", (Class<?>[]) null);
            if (null != m) {
                m.invoke(reporter, (Object[]) null);
                success = true;
            } else {
                logger.warn("Unable to locate a start() method on Reporter: {}", reporter.getClass());
            }
        } else {
            // look for a start(long,TimeUnit) method
            Method m = reporter.getClass().getMethod("start", long.class, TimeUnit.class);
            if (null != m) {
                m.invoke(reporter, reporterFactory.getInterval(), reporterFactory.getTimeUnit());
                success = true;
            } else {
                logger.warn("Unable to locate a start(long,TimeUnit) method on Reporter: {}", reporter.getClass());
            }
        }
    } catch (Throwable t) {
        logger.warn("Unable to start reporter of type {}", reporter.getClass(), t);
    }
    return success;
}
Also used : ScheduledReporter(com.codahale.metrics.ScheduledReporter) Reporter(com.codahale.metrics.Reporter) ScheduledReporter(com.codahale.metrics.ScheduledReporter) Method(java.lang.reflect.Method)

Aggregations

Reporter (com.codahale.metrics.Reporter)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 ScheduledReporter (com.codahale.metrics.ScheduledReporter)1 Method (java.lang.reflect.Method)1 Test (org.junit.Test)1