Search in sources :

Example 1 with JmxReporter

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

the class CodahaleMetrics method initReporting.

/**
   * Should be only called once to initialize the reporters
   */
private void initReporting(Set<MetricsReporting> reportingSet) {
    for (MetricsReporting reporting : reportingSet) {
        switch(reporting) {
            case CONSOLE:
                final ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
                consoleReporter.start(1, TimeUnit.SECONDS);
                reporters.add(consoleReporter);
                break;
            case JMX:
                final JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
                jmxReporter.start();
                reporters.add(jmxReporter);
                break;
            case JSON_FILE:
                final JsonFileReporter jsonFileReporter = new JsonFileReporter();
                jsonFileReporter.start();
                reporters.add(jsonFileReporter);
                break;
            case HADOOP2:
                String applicationName = conf.get(HiveConf.ConfVars.HIVE_METRICS_HADOOP2_COMPONENT_NAME.varname);
                long reportingInterval = HiveConf.toTime(conf.get(HiveConf.ConfVars.HIVE_METRICS_HADOOP2_INTERVAL.varname), TimeUnit.SECONDS, TimeUnit.SECONDS);
                final HadoopMetrics2Reporter metrics2Reporter = HadoopMetrics2Reporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build(// The application-level name
                DefaultMetricsSystem.initialize(applicationName), // Component name
                applicationName, // Component description
                applicationName, // Name for each metric record
                "General");
                metrics2Reporter.start(reportingInterval, TimeUnit.SECONDS);
                break;
        }
    }
}
Also used : HadoopMetrics2Reporter(com.github.joshelser.dropwizard.metrics.hadoop.HadoopMetrics2Reporter) ConsoleReporter(com.codahale.metrics.ConsoleReporter) JmxReporter(com.codahale.metrics.JmxReporter)

Example 2 with JmxReporter

use of com.codahale.metrics.JmxReporter in project sockjs-netty by cgbystrom.

the class StressTestServer method start.

public void start() throws Exception {
    final JmxReporter reporter = JmxReporter.forRegistry(registry).build();
    final ServiceRouter router = new ServiceRouter();
    reporter.start();
    router.setMetricRegistry(registry);
    Service echoService = new Service("/stresstest", new SessionCallbackFactory() {

        @Override
        public StressTestSession getSession(String id) throws Exception {
            return new StressTestSession();
        }
    });
    router.registerService(echoService);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = pipeline();
            pipeline.addLast("decoder", new HttpRequestDecoder());
            // Required for WS handshaker or else NPE.
            pipeline.addLast("chunkAggregator", new HttpChunkAggregator(130 * 1024));
            pipeline.addLast("encoder", new HttpResponseEncoder());
            pipeline.addLast("preflight", new PreflightHandler());
            pipeline.addLast("router", router);
            return pipeline;
        }
    });
    bootstrap.bind(new LocalAddress(port));
}
Also used : LocalAddress(org.jboss.netty.channel.local.LocalAddress) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) JmxReporter(com.codahale.metrics.JmxReporter) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory)

Example 3 with JmxReporter

use of com.codahale.metrics.JmxReporter in project sockjs-netty by cgbystrom.

the class TestServer method main.

public static void main(String[] args) {
    Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    LoggerContext loggerContext = rootLogger.getLoggerContext();
    loggerContext.reset();
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(loggerContext);
    encoder.setPattern("%-5level %-20class{0}: %message%n");
    encoder.start();
    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
    appender.setContext(loggerContext);
    appender.setEncoder(encoder);
    appender.start();
    rootLogger.addAppender(appender);
    InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
    ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    final MetricRegistry registry = new MetricRegistry();
    final JmxReporter reporter = JmxReporter.forRegistry(registry).build();
    reporter.start();
    final ServiceRouter router = new ServiceRouter();
    router.setMetricRegistry(registry);
    router.registerService(new Service("/disabled_websocket_echo", new DisabledWebSocketEchoSession()));
    router.registerService(new Service("/close", new CloseSession()));
    router.registerService(new Service("/amplify", new AmplifySession()));
    router.registerService(new Service("/broadcast", new SessionCallbackFactory() {

        @Override
        public BroadcastSession getSession(String id) throws Exception {
            return new BroadcastSession();
        }
    }));
    Service echoService = new Service("/echo", new SessionCallbackFactory() {

        @Override
        public EchoSession getSession(String id) throws Exception {
            return new EchoSession();
        }
    });
    echoService.setMaxResponseSize(4096);
    router.registerService(echoService);
    Service cookieNeededEcho = new Service("/cookie_needed_echo", new EchoSession());
    cookieNeededEcho.setMaxResponseSize(4096);
    cookieNeededEcho.setCookieNeeded(true);
    router.registerService(cookieNeededEcho);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = pipeline();
            pipeline.addLast("decoder", new HttpRequestDecoder());
            // Required for WS handshaker or else NPE.
            pipeline.addLast("chunkAggregator", new HttpChunkAggregator(130 * 1024));
            pipeline.addLast("encoder", new HttpResponseEncoder());
            pipeline.addLast("preflight", new PreflightHandler());
            pipeline.addLast("router", router);
            return pipeline;
        }
    });
    bootstrap.bind(new InetSocketAddress(8090));
    System.out.println("Server running..");
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) InetSocketAddress(java.net.InetSocketAddress) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) Slf4JLoggerFactory(org.jboss.netty.logging.Slf4JLoggerFactory) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) BroadcastSession(com.cgbystrom.sockjs.test.BroadcastSession) LoggerContext(ch.qos.logback.classic.LoggerContext) JmxReporter(com.codahale.metrics.JmxReporter) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory)

Example 4 with JmxReporter

use of com.codahale.metrics.JmxReporter in project opennms by OpenNMS.

the class CamelLocalMessageDispatcherFactory method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    final JmxReporter reporter = JmxReporter.forRegistry(getMetrics()).inDomain(CamelLocalMessageDispatcherFactory.class.getPackage().getName()).build();
    reporter.start();
}
Also used : JmxReporter(com.codahale.metrics.JmxReporter)

Example 5 with JmxReporter

use of com.codahale.metrics.JmxReporter in project ninja by ninjaframework.

the class MetricsServiceImpl method start.

@Start(order = 10)
@Override
public void start() {
    String applicationName = ninjaProps.getWithDefault(NinjaConstant.applicationName, "Ninja");
    /*
         * Register optional metrics
         */
    if (ninjaProps.getBooleanWithDefault("metrics.jvm.enabled", false)) {
        registerAll("jvm.gc", new GarbageCollectorMetricSet());
        registerAll("jvm.memory", new MemoryUsageGaugeSet());
        registerAll("jvm.threads", new ThreadStatesGaugeSet());
        registerAll("jvm.classes", new ClassLoadingGaugeSet());
        log.debug("Registered JVM-Metrics integration");
    }
    if (ninjaProps.getBooleanWithDefault("metrics.logback.enabled", false)) {
        final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory();
        final ch.qos.logback.classic.Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME);
        final InstrumentedAppender appender = new InstrumentedAppender(metricRegistry);
        appender.setContext(root.getLoggerContext());
        appender.start();
        root.addAppender(appender);
        log.debug("Registered Logback-Metrics integration");
    }
    /*
         * MBeans for VisualVM, JConsole, or JMX
         */
    if (ninjaProps.getBooleanWithDefault("metrics.mbeans.enabled", true)) {
        JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).inDomain(applicationName).build();
        reporter.start();
        reporters.add(reporter);
        log.debug("Started Ninja Metrics MBeans reporter");
    }
    log.info("Ninja Metrics is ready for collection.");
}
Also used : InstrumentedAppender(com.codahale.metrics.logback.InstrumentedAppender) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) ClassLoadingGaugeSet(com.codahale.metrics.jvm.ClassLoadingGaugeSet) ThreadStatesGaugeSet(com.codahale.metrics.jvm.ThreadStatesGaugeSet) LoggerContext(ch.qos.logback.classic.LoggerContext) JmxReporter(com.codahale.metrics.JmxReporter) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet) Start(ninja.lifecycle.Start)

Aggregations

JmxReporter (com.codahale.metrics.JmxReporter)8 MetricRegistry (com.codahale.metrics.MetricRegistry)3 LoggerContext (ch.qos.logback.classic.LoggerContext)2 Injector (com.google.inject.Injector)2 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)2 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)2 HttpChunkAggregator (org.jboss.netty.handler.codec.http.HttpChunkAggregator)2 HttpRequestDecoder (org.jboss.netty.handler.codec.http.HttpRequestDecoder)2 HttpResponseEncoder (org.jboss.netty.handler.codec.http.HttpResponseEncoder)2 Logger (ch.qos.logback.classic.Logger)1 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)1 BroadcastSession (com.cgbystrom.sockjs.test.BroadcastSession)1 ConsoleReporter (com.codahale.metrics.ConsoleReporter)1 ClassLoadingGaugeSet (com.codahale.metrics.jvm.ClassLoadingGaugeSet)1 GarbageCollectorMetricSet (com.codahale.metrics.jvm.GarbageCollectorMetricSet)1 MemoryUsageGaugeSet (com.codahale.metrics.jvm.MemoryUsageGaugeSet)1 ThreadStatesGaugeSet (com.codahale.metrics.jvm.ThreadStatesGaugeSet)1 InstrumentedAppender (com.codahale.metrics.log4j2.InstrumentedAppender)1