Search in sources :

Example 1 with AbstractHttpServer

use of loghub.netty.http.AbstractHttpServer 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)

Aggregations

JCommander (com.beust.jcommander.JCommander)1 Parameter (com.beust.jcommander.Parameter)1 ParameterException (com.beust.jcommander.ParameterException)1 JmxReporter (com.codahale.metrics.jmx.JmxReporter)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ManagementFactory (java.lang.management.ManagementFactory)1 NotBoundException (java.rmi.NotBoundException)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 MBeanServer (javax.management.MBeanServer)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 ObjectName (javax.management.ObjectName)1 ConfigException (loghub.configuration.ConfigException)1 Configuration (loghub.configuration.Configuration)1 Properties (loghub.configuration.Properties)1 TestEventProcessing (loghub.configuration.TestEventProcessing)1