Search in sources :

Example 1 with ScheduledReporter

use of com.codahale.metrics.ScheduledReporter 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)

Example 2 with ScheduledReporter

use of com.codahale.metrics.ScheduledReporter in project pravega by pravega.

the class StatsProviderImpl method start.

@Synchronized
@Override
public void start() {
    init();
    if (conf.isEnableCSVReporter()) {
        // NOTE:  metrics output files are exclusive to a given process
        File outdir;
        if (!Strings.isNullOrEmpty(conf.getMetricsPrefix())) {
            outdir = new File(conf.getCsvEndpoint(), conf.getMetricsPrefix());
        } else {
            outdir = new File(conf.getCsvEndpoint());
        }
        outdir.mkdirs();
        log.info("Configuring stats with csv output to directory [{}]", outdir.getAbsolutePath());
        reporters.add(CsvReporter.forRegistry(getMetrics()).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build(outdir));
    }
    if (conf.isEnableStatsdReporter()) {
        log.info("Configuring stats with statsD at {}:{}", conf.getStatsDHost(), conf.getStatsDPort());
        reporters.add(StatsDReporter.forRegistry(getMetrics()).build(conf.getStatsDHost(), conf.getStatsDPort()));
    }
    if (conf.isEnableGraphiteReporter()) {
        log.info("Configuring stats with graphite at {}:{}", conf.getGraphiteHost(), conf.getGraphitePort());
        final Graphite graphite = new Graphite(new InetSocketAddress(conf.getGraphiteHost(), conf.getGraphitePort()));
        reporters.add(GraphiteReporter.forRegistry(getMetrics()).prefixedWith(conf.getMetricsPrefix()).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(graphite));
    }
    if (conf.isEnableJMXReporter()) {
        log.info("Configuring stats with jmx {}", conf.getJmxDomain());
        final JmxReporter jmx = JmxReporter.forRegistry(getMetrics()).inDomain(conf.getJmxDomain()).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
        jmx.start();
    }
    if (conf.isEnableGangliaReporter()) {
        try {
            log.info("Configuring stats with ganglia at {}:{}", conf.getGangliaHost(), conf.getGangliaPort());
            final GMetric ganglia = new GMetric(conf.getGangliaHost(), conf.getGangliaPort(), GMetric.UDPAddressingMode.MULTICAST, 1);
            reporters.add(GangliaReporter.forRegistry(getMetrics()).prefixedWith(conf.getMetricsPrefix()).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build(ganglia));
        } catch (IOException e) {
            log.warn("ganglia create failure: {}", e);
        }
    }
    if (conf.isEnableConsoleReporter()) {
        log.info("Configuring console reporter");
        reporters.add(ConsoleReporter.forRegistry(getMetrics()).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build());
    }
    for (ScheduledReporter r : reporters) {
        r.start(conf.getStatsOutputFrequencySeconds(), TimeUnit.SECONDS);
    }
}
Also used : GMetric(info.ganglia.gmetric4j.gmetric.GMetric) InetSocketAddress(java.net.InetSocketAddress) Graphite(com.codahale.metrics.graphite.Graphite) IOException(java.io.IOException) ScheduledReporter(com.codahale.metrics.ScheduledReporter) File(java.io.File) JmxReporter(com.codahale.metrics.JmxReporter) Synchronized(lombok.Synchronized)

Example 3 with ScheduledReporter

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

the class Metrics method shutdown.

public static void shutdown() {
    if (self != null) {
        for (ScheduledReporter reporter : self.scheduledReporters) {
            reporter.stop();
            reporter.close();
        }
        if (self.hadoopMetricsStarted)
            DefaultMetricsSystem.shutdown();
        self = null;
    }
}
Also used : ScheduledReporter(com.codahale.metrics.ScheduledReporter)

Example 4 with ScheduledReporter

use of com.codahale.metrics.ScheduledReporter in project pravega by pravega.

the class StatsProviderImpl method close.

@Synchronized
@Override
public void close() {
    for (ScheduledReporter r : reporters) {
        try {
            r.report();
            r.stop();
        } catch (Exception e) {
            log.error("Exception report or stop reporter", e);
        }
    }
    metrics.removeMatching(MetricFilter.ALL);
}
Also used : ScheduledReporter(com.codahale.metrics.ScheduledReporter) IOException(java.io.IOException) Synchronized(lombok.Synchronized)

Aggregations

ScheduledReporter (com.codahale.metrics.ScheduledReporter)4 IOException (java.io.IOException)2 Synchronized (lombok.Synchronized)2 JmxReporter (com.codahale.metrics.JmxReporter)1 Reporter (com.codahale.metrics.Reporter)1 Graphite (com.codahale.metrics.graphite.Graphite)1 GMetric (info.ganglia.gmetric4j.gmetric.GMetric)1 File (java.io.File)1 Method (java.lang.reflect.Method)1 InetSocketAddress (java.net.InetSocketAddress)1