Search in sources :

Example 6 with JmxReporter

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

the class NewtsService method run.

@Override
public void run(final NewtsConfig config, Environment environment) throws Exception {
    // Filters
    configureCors(environment);
    configureUIRedirect(environment);
    configureAuthentication(environment, config);
    final Injector injector = Guice.createInjector(new NewtsGuiceModule(), new CassandraGuiceModule(config), new GraphiteGuiceModule(config));
    MetricRegistry metricRegistry = injector.getInstance(MetricRegistry.class);
    // Create/start a JMX reporter for our MetricRegistry
    final JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).inDomain("newts").build();
    // Create (and start if so configured), a Graphite line-protocol listener
    final GraphiteListenerThread listener = new GraphiteListenerThread(injector.getInstance(GraphiteListener.class));
    environment.lifecycle().manage(new Managed() {

        @Override
        public void stop() throws Exception {
            reporter.stop();
        }

        @Override
        public void start() throws Exception {
            reporter.start();
            if (config.getGraphiteConfig().isEnabled()) {
                listener.start();
            }
        }
    });
    SampleRepository repository = injector.getInstance(SampleRepository.class);
    Indexer indexer = injector.getInstance(Indexer.class);
    // Rest resources
    environment.jersey().register(new MeasurementsResource(repository, config.getReports()));
    environment.jersey().register(new SamplesResource(repository, indexer));
    // Add search resource only if search is enabled
    if (config.getSearchConfig().isEnabled()) {
        environment.jersey().register(new SearchResource(injector.getInstance(Searcher.class)));
    }
    // Health checks
    environment.healthChecks().register("repository", new RepositoryHealthCheck(repository));
    // Mapped exceptions
    environment.jersey().register(IllegalArgumentExceptionMapper.class);
}
Also used : SampleRepository(org.opennms.newts.api.SampleRepository) MetricRegistry(com.codahale.metrics.MetricRegistry) JmxReporter(com.codahale.metrics.JmxReporter) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Indexer(org.opennms.newts.api.search.Indexer) Injector(com.google.inject.Injector) GraphiteListener(org.opennms.newts.graphite.GraphiteListener) Managed(io.dropwizard.lifecycle.Managed)

Example 7 with JmxReporter

use of com.codahale.metrics.JmxReporter in project graylog2-server by Graylog2.

the class CmdLineTool method run.

@Override
public void run() {
    final Level logLevel = setupLogger();
    final PluginBindings pluginBindings = installPluginConfigAndBindings(getPluginPath(configFile), chainingClassLoader);
    if (isDumpDefaultConfig()) {
        dumpDefaultConfigAndExit();
    }
    final NamedConfigParametersModule configModule = readConfiguration(configFile);
    if (isDumpConfig()) {
        dumpCurrentConfigAndExit();
    }
    if (!validateConfiguration()) {
        LOG.error("Validating configuration file failed - exiting.");
        System.exit(1);
    }
    beforeStart();
    final List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
    LOG.info("Running with JVM arguments: {}", Joiner.on(' ').join(arguments));
    injector = setupInjector(configModule, pluginBindings, binder -> binder.bind(ChainingClassLoader.class).toInstance(chainingClassLoader));
    if (injector == null) {
        LOG.error("Injector could not be created, exiting! (Please include the previous error messages in bug reports.)");
        System.exit(1);
    }
    // This is holding all our metrics.
    final MetricRegistry metrics = injector.getInstance(MetricRegistry.class);
    addInstrumentedAppender(metrics, logLevel);
    // Report metrics via JMX.
    final JmxReporter reporter = JmxReporter.forRegistry(metrics).build();
    reporter.start();
    startCommand();
}
Also used : NamedConfigParametersModule(com.github.joschi.jadconfig.guice.NamedConfigParametersModule) Option(com.github.rvesse.airline.annotations.Option) Module(com.google.inject.Module) Plugin(org.graylog2.plugin.Plugin) Arrays(java.util.Arrays) ParameterException(com.github.joschi.jadconfig.ParameterException) NodeIdPersistenceException(org.graylog2.plugin.system.NodeIdPersistenceException) GuiceInjectorHolder(org.graylog2.shared.bindings.GuiceInjectorHolder) RepositoryException(com.github.joschi.jadconfig.RepositoryException) LoggerContext(org.apache.logging.log4j.core.LoggerContext) Tools(org.graylog2.plugin.Tools) LoggerFactory(org.slf4j.LoggerFactory) Level(org.apache.logging.log4j.Level) InstrumentedAppender(com.codahale.metrics.log4j2.InstrumentedAppender) Slf4JLoggerFactory(org.jboss.netty.logging.Slf4JLoggerFactory) Message(com.google.inject.spi.Message) PluginLoaderConfig(org.graylog2.plugin.PluginLoaderConfig) Map(java.util.Map) InternalLoggerFactory(org.jboss.netty.logging.InternalLoggerFactory) Version(org.graylog2.plugin.Version) JmxReporter(com.codahale.metrics.JmxReporter) PropertiesRepository(com.github.joschi.jadconfig.repositories.PropertiesRepository) Command(com.github.rvesse.airline.annotations.Command) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader) PluginModule(org.graylog2.plugin.PluginModule) ExceptionUtils(org.graylog2.shared.utilities.ExceptionUtils) JodaTimeConverterFactory(com.github.joschi.jadconfig.jodatime.JodaTimeConverterFactory) Collection(java.util.Collection) Set(java.util.Set) ServerStatus(org.graylog2.plugin.ServerStatus) ValidationException(com.github.joschi.jadconfig.ValidationException) Sets(com.google.common.collect.Sets) List(java.util.List) PluginBindings(org.graylog2.shared.bindings.PluginBindings) PluginMetaData(org.graylog2.plugin.PluginMetaData) UI(org.graylog2.shared.UI) AccessDeniedException(java.nio.file.AccessDeniedException) GuavaConverterFactory(com.github.joschi.jadconfig.guava.GuavaConverterFactory) Joiner(com.google.common.base.Joiner) EnvironmentRepository(com.github.joschi.jadconfig.repositories.EnvironmentRepository) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Binder(com.google.inject.Binder) SystemPropertiesRepository(com.github.joschi.jadconfig.repositories.SystemPropertiesRepository) JadConfig(com.github.joschi.jadconfig.JadConfig) ManagementFactory(java.lang.management.ManagementFactory) NamedConfigParametersModule(com.github.joschi.jadconfig.guice.NamedConfigParametersModule) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) PluginConfigBean(org.graylog2.plugin.PluginConfigBean) Names(com.google.inject.name.Names) PluginLoader(org.graylog2.shared.plugins.PluginLoader) File(java.io.File) Injector(com.google.inject.Injector) CreationException(com.google.inject.CreationException) Repository(com.github.joschi.jadconfig.Repository) BaseConfiguration(org.graylog2.plugin.BaseConfiguration) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) PluginBindings(org.graylog2.shared.bindings.PluginBindings) MetricRegistry(com.codahale.metrics.MetricRegistry) Level(org.apache.logging.log4j.Level) JmxReporter(com.codahale.metrics.JmxReporter) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader)

Example 8 with JmxReporter

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

the class KafkaLocalMessageDispatcherFactory method afterPropertiesSet.

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

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