Search in sources :

Example 1 with JmxReporter

use of com.codahale.metrics.jmx.JmxReporter in project LogHub by fbacchella.

the class Start method launch.

public void launch(Properties props) throws ConfigException, IOException {
    for (Source s : props.sources.values()) {
        if (!s.configure(props)) {
            logger.error("failed to start source {}", s.getName());
            throw new IllegalStateException();
        }
        ;
    }
    props.pipelines.stream().forEach(i -> i.configure(props));
    for (Sender s : props.senders) {
        if (s.configure(props)) {
            s.start();
        } else {
            logger.error("failed to configure output {}", s.getName());
            throw new IllegalStateException();
        }
        ;
    }
    for (int i = 0; i < props.numWorkers; i++) {
        Thread t = new EventsProcessor(props.mainQueue, props.outputQueues, props.namedPipeLine, props.maxSteps, props.repository);
        t.setName("ProcessingThread" + i);
        t.setDaemon(false);
        t.start();
    }
    for (Receiver r : props.receivers) {
        if (r.configure(props)) {
            r.start();
        } else {
            logger.error("failed to configure input {}", r.getName());
            throw new IllegalStateException();
        }
    }
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        mbs.registerMBean(new StatsMBean.Implementation(), StatsMBean.Implementation.NAME);
        JmxReporter reporter = Properties.metrics.getJmxReporter();
        reporter.start();
        mbs.queryNames(ObjectName.getInstance("metrics", "name", "Pipeline.*.timer"), null).stream().map(i -> i.getKeyProperty("name")).map(i -> i.replaceAll("^Pipeline\\.(.*)\\.timer$", "$1")).forEach(i -> {
            try {
                mbs.registerMBean(new PipelineStat.Implementation(i), null);
            } catch (NotCompliantMBeanException | InstanceAlreadyExistsException | MBeanRegistrationException e) {
            }
        });
        int port = props.jmxport;
        if (port > 0) {
            Helper.start(props.jmxproto, props.jmxlisten, port);
        }
    } catch (IOException | NotBoundException | NotCompliantMBeanException | MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException e) {
        throw new RuntimeException("jmx configuration failed: " + e.getMessage(), e);
    }
    if (props.httpPort >= 0) {
        AbstractHttpServer server = new DashboardHttpServer();
        server.setPort(props.httpPort);
        server.configure(props);
    }
}
Also used : PipelineStat(loghub.jmx.PipelineStat) ParameterException(com.beust.jcommander.ParameterException) Parameter(com.beust.jcommander.Parameter) AbstractHttpServer(loghub.netty.http.AbstractHttpServer) ConfigException(loghub.configuration.ConfigException) JmxReporter(com.codahale.metrics.jmx.JmxReporter) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanServer(javax.management.MBeanServer) MBeanRegistrationException(javax.management.MBeanRegistrationException) ManagementFactory(java.lang.management.ManagementFactory) NotBoundException(java.rmi.NotBoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) FieldsProcessor(loghub.processors.FieldsProcessor) JCommander(com.beust.jcommander.JCommander) IOException(java.io.IOException) TestEventProcessing(loghub.configuration.TestEventProcessing) ObjectName(javax.management.ObjectName) StatsMBean(loghub.jmx.StatsMBean) InputStreamReader(java.io.InputStreamReader) MalformedObjectNameException(javax.management.MalformedObjectNameException) Logger(org.apache.logging.log4j.Logger) Helper(loghub.jmx.Helper) Configuration(loghub.configuration.Configuration) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LogManager(org.apache.logging.log4j.LogManager) Properties(loghub.configuration.Properties) NotBoundException(java.rmi.NotBoundException) AbstractHttpServer(loghub.netty.http.AbstractHttpServer) MBeanServer(javax.management.MBeanServer) MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) IOException(java.io.IOException) JmxReporter(com.codahale.metrics.jmx.JmxReporter) StatsMBean(loghub.jmx.StatsMBean) PipelineStat(loghub.jmx.PipelineStat) MBeanRegistrationException(javax.management.MBeanRegistrationException)

Example 2 with JmxReporter

use of com.codahale.metrics.jmx.JmxReporter in project cxf by apache.

the class CodahaleMetricsProvider method setupJMXReporter.

public static void setupJMXReporter(Bus b, MetricRegistry reg) {
    InstrumentationManager im = b.getExtension(InstrumentationManager.class);
    if (im != null) {
        JmxReporter reporter = JmxReporter.forRegistry(reg).registerWith(im.getMBeanServer()).inDomain("org.apache.cxf").createsObjectNamesWith(new ObjectNameFactory() {

            public ObjectName createName(String type, String domain, String name) {
                try {
                    return new ObjectName(name);
                } catch (MalformedObjectNameException e) {
                    throw new RuntimeException(e);
                }
            }
        }).build();
        reporter.start();
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) ObjectNameFactory(com.codahale.metrics.jmx.ObjectNameFactory) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) JmxReporter(com.codahale.metrics.jmx.JmxReporter) ObjectName(javax.management.ObjectName)

Example 3 with JmxReporter

use of com.codahale.metrics.jmx.JmxReporter in project wikidata-query-rdf by wikimedia.

the class Update method createMetricRegistry.

private static MetricRegistry createMetricRegistry(Closer closer, String metricDomain) {
    MetricRegistry metrics = new MetricRegistry();
    JmxReporter reporter = closer.register(JmxReporter.forRegistry(metrics).inDomain(metricDomain).build());
    reporter.start();
    return metrics;
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) JmxReporter(com.codahale.metrics.jmx.JmxReporter)

Example 4 with JmxReporter

use of com.codahale.metrics.jmx.JmxReporter in project wikidata-query-rdf by wikimedia.

the class WikibaseContextListener method createMetricRegistry.

private MetricRegistry createMetricRegistry() {
    MetricRegistry registry = new MetricRegistry();
    JmxReporter jmxReporter = JmxReporter.forRegistry(registry).inDomain(METRICS_DOMAIN).build();
    jmxReporter.start();
    shutdownHooks.add(jmxReporter::stop);
    return registry;
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) JmxReporter(com.codahale.metrics.jmx.JmxReporter)

Example 5 with JmxReporter

use of com.codahale.metrics.jmx.JmxReporter in project wikidata-query-rdf by wikimedia.

the class StreamingUpdate method main.

public static void main(String[] args) {
    log.info("Starting StreamingUpdater");
    StreamingUpdateOptions options = OptionsUtils.handleOptions(StreamingUpdateOptions.class, args);
    MetricRegistry metrics = new MetricRegistry();
    JmxReporter reporter = JmxReporter.forRegistry(metrics).inDomain(options.metricDomain()).build();
    StreamingUpdaterConsumer updater = build(options, metrics);
    Thread streamingUpdaterThread = Thread.currentThread();
    streamingUpdaterThread.setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception in the updater thread: ", e));
    addShutdownHook(updater, streamingUpdaterThread, reporter);
    reporter.start();
    updater.run();
}
Also used : StreamingUpdateOptions(org.wikidata.query.rdf.updater.consumer.options.StreamingUpdateOptions) MetricRegistry(com.codahale.metrics.MetricRegistry) JmxReporter(com.codahale.metrics.jmx.JmxReporter)

Aggregations

JmxReporter (com.codahale.metrics.jmx.JmxReporter)11 MetricRegistry (com.codahale.metrics.MetricRegistry)9 VerifiableProperties (com.github.ambry.config.VerifiableProperties)5 ObjectNameFactory (com.codahale.metrics.jmx.ObjectNameFactory)4 DefaultObjectNameFactory (com.codahale.metrics.jmx.DefaultObjectNameFactory)3 IOException (java.io.IOException)3 Collections (java.util.Collections)3 Properties (java.util.Properties)3 Function (java.util.function.Function)3 Test (org.junit.Test)3 Mockito (org.mockito.Mockito)3 MockClusterAgentsFactory (com.github.ambry.clustermap.MockClusterAgentsFactory)2 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)2 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)2 SSLFactory (com.github.ambry.commons.SSLFactory)2 NotificationSystem (com.github.ambry.notification.NotificationSystem)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 ObjectName (javax.management.ObjectName)2 Assert (org.junit.Assert)2 JCommander (com.beust.jcommander.JCommander)1