带弹簧靴的Graylog。 (graylog无法成功连接)

时间:2016-08-17 05:54:59

标签: maven spring-boot swagger swagger-ui graylog2

 final Cli<CliCommand> cli = builder.build();
    final Runnable command = cli.parse("server", "-f", graylogConfigFile);
    final Thread graylogThread = new Thread(command);

    /*
    This is a nasty workaround to get Graylog's Swagger instance working when embedded within SpringBoot.
    DocumentationBrowserResource uses the SystemClassLoader (which it 100% should not be doing) which means
    it fails to load resources when run in an environment like SpringBoot
     */
    try {
        Field sclField = ReflectionUtils.findField(ClassLoader.class, "scl");
        ReflectionUtils.makeAccessible(sclField);
        ReflectionUtils.setField(sclField, null, new DecoratingClassLoader() {
            @Override
            public URL getResource(String name) {
                if (name.startsWith("swagger/")) {
                    return Thread.currentThread().getContextClassLoader().getResource(name);
                }
                return super.getResource(name);
            }
        });
    } catch(Exception e) {
        LOGGER.error("Failed to replace SystemClassLoader, this means Graylog's Swagger won't work.", e);
    }

    graylogThread.start();

    LOGGER.info("Graylog started");

    configureGraylog();
}

private void configureGraylog() {
    try {
        graylogRestInterface.inputExists("test");
        LOGGER.info("Graylog rest interface ready to go!");

        setupUdpInput();
        setupHttpInput();
        setupDashboard();
    } catch (Exception e) {
        LOGGER.warn("Graylog rest interface not ready yet, rescheduling...");
        delay(this::configureGraylog, 1);
    }
}

private void delay(Runnable runnable, int delaySeconds) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.SECOND, delaySeconds);
    scheduler.schedule(runnable, cal.getTime());
}

private void setupUdpInput() {
    String inputName = "SpringBoot GELF UDP";
    if (graylogRestInterface.inputExists(inputName)) {
        LOGGER.info("Graylog UDP input already exists, skipping...");
        return;
    }
    setupInput(inputName, GELFUDPInput.class, 12201);
}

private void setupHttpInput() {
    String inputName = "SpringBoot GELF HTTP";
    if (graylogRestInterface.inputExists(inputName)) {
        LOGGER.info("Graylog HTTP input already exists, skipping...");
        return;
    }
    String inputId = setupInput(inputName, GELFHttpInput.class, 12202);

    Map<String, Object> extractorConfig = new HashMap<>();
    extractorConfig.put("key_separator", "_");
    extractorConfig.put("list_separator", ", ");
    extractorConfig.put("kv_separator", "=");
    CreateExtractorRequest extractorRequest = CreateExtractorRequest.create(
            "Quote JSON",
            "copy",
            "full_message",
            "",
            "json",
            extractorConfig,
            Collections.emptyMap(),
            "none",
            "",
            0
    );
    graylogRestInterface.createExtractor(inputId, extractorRequest);
    LOGGER.info("Graylog JSON extractor created.");
}

private String setupInput(String name, Class<? extends MessageInput> inputType, int port) {
    Map<String, Object> properties = new HashMap<>();
    properties.put("use_null_delimiter", true);
    properties.put("bind_address", "0.0.0.0");
    properties.put("port", port);

    InputCreateRequest request = InputCreateRequest.create(
            name,
            inputType.getName(),
            true,
            properties,
            null);

    String inputId = graylogRestInterface.createInput(request);
    LOGGER.info(String.format("%s input created.", name));
    return inputId;
}

private void setupDashboard() {
    String dashboardName = "Stock Market";
    if (graylogRestInterface.dashboardExists(dashboardName)) {
        LOGGER.info("Graylog dashboard already exists, skipping...");
        return;
    }
    CreateDashboardRequest dashboardRequest = CreateDashboardRequest.create(
            dashboardName,
            "Measurements from Stock Market example application"
    );

    String dashboardId = graylogRestInterface.createDashboard(dashboardRequest);
    LOGGER.info("Graylog dashboard created.");

    Map<String, Object> timerangeMap = new HashMap<String, Object>() {{
        put("type", "relative");
        put("range", 300);
    }};

    AddWidgetRequest widgetRequest = AddWidgetRequest.create(
            "Stock Quotes - Symbols",
            "QUICKVALUES",
            10,
            new HashMap<String, Object>(){{
                    put("timerange", timerangeMap);
                    put("field", "symbol");
                    put("show_pie_chart", true);
                    put("query", "");
                    put("show_data_table", true);
            }}
    );
    graylogRestInterface.createWidget(dashboardId, widgetRequest);
    LOGGER.info("Symbol widget created.");

    widgetRequest = AddWidgetRequest.create(
            "Generated Quote Count",
            "SEARCH_RESULT_COUNT",
            10,
            new HashMap<String, Object>(){{
                put("timerange", timerangeMap);
                put("lower_is_better", false);
                put("trend", false);
                put("query", "_exists_:symbol");
            }}
    );
    graylogRestInterface.createWidget(dashboardId, widgetRequest);
    LOGGER.info("Quote count widget created.");

    widgetRequest = AddWidgetRequest.create(
            "Quote Generation Time (us)",
            "FIELD_CHART",
            10,
            new HashMap<String, Object>(){{
                put("timerange", new HashMap<String, Object>() {{
                    put("type", "relative");
                    put("range", 300);
                }});
                put("valuetype", "mean");
                put("renderer", "line");
                put("interpolation", "linear");
                put("field", "elapsed_time");
                put("interval", "minute");
                put("rangeType", "relative");
                put("relative", 300);
                put("query", "_exists_:elapsed_time");
            }}
    );
    graylogRestInterface.createWidget(dashboardId, widgetRequest);
    LOGGER.info("Quote generation time widget created.");

    widgetRequest = AddWidgetRequest.create(
            "Error Count",
            "SEARCH_RESULT_COUNT",
            10,
            new HashMap<String, Object>(){{
                put("timerange", new HashMap<String, Object>() {{
                    put("type", "relative");
                    put("range", 300);
                }});
                put("lower_is_better", false);
                put("trend", false);
                put("query", "_exists_:stacktrace");
            }}
    );
    graylogRestInterface.createWidget(dashboardId, widgetRequest);
    LOGGER.info("Error count widget created.");
}
  

2016-08-17 10:53:29,439 INFO GraylogInstance:101:Graylog开始2016-08-17 10:53:29,763 WARN GraylogInstance:115:Graylog rest   界面尚未准备好,重新安排... 2016-08-17 10:53:30.583警告   4037 --- [Thread-1] o.graylog2.shared.plugins.PluginLoader:插件   目录   /家庭/ govindj / projectworkspace / graylog-springboot主/数据/插件   不存在,不加载插件。 2016-08-17 10:53:30.592 INFO 4037   --- [Thread-1] org.graylog2.bootstrap.CmdLineTool:已加载的插件:[] 2016-08-17 10:53:30.593 INFO 4037 --- [Thread-1]   com.github.joschi.jadconfig.JadConfig:添加了配置bean   org.graylog2.Configuration@8811ccc 2016-08-17 10:53:30.594 INFO 4037   --- [Thread-1] com.github.joschi.jadconfig.JadConfig:添加了配置bean   org.graylog2.configuration.ElasticsearchConfiguration@adafa1b   2016-08-17 10:53:30.594 INFO 4037 --- [Thread-1]   com.github.joschi.jadconfig.JadConfig:添加了配置bean   org.graylog2.configuration.EmailConfiguration@61bd14b1 2016-08-17   10:53:30.594 INFO 4037 --- [Thread-1]   com.github.joschi.jadconfig.JadConfig:添加了配置bean   org.graylog2.configuration.MongoDbConfiguration@6019bdc6 2016-08-17   10:53:30.594 INFO 4037 --- [Thread-1]   com.github.joschi.jadconfig.JadConfig:添加了配置bean   org.graylog2.configuration.VersionCheckConfiguration@60feba75   2016-08-17 10:53:30.594 INFO 4037 --- [Thread-1]   com.github.joschi.jadconfig.JadConfig:添加了配置bean   org.graylog2.plugin.KafkaJournalConfiguration@3d299e53 2016-08-17   10:53:30.705 INFO 4037 --- [Thread-1]   org.graylog2.bootstrap.CmdLineTool:使用JVM参数运行:   -Dfile.encoding = UTF-8 2016-08-17 10:53:30,775 WARN GraylogInstance:115:Graylog休息界面尚未准备好,重新安排... 2016-08-17   10:53:31.163 INFO 4037 --- [主要]   s.w.s.m.m.a.RequestMappingHandlerMapping:已映射   &#34; {[/报价/ {符号}],方法= [GET]}&#34;公共空白   com.objectpartners.plummer.graylog.controller.QuotesController.getQuote(java.lang.String中)   2016-08-17 10:53:31.172 INFO 4037 --- [主要]   s.w.s.m.m.a.RequestMappingHandlerMapping:已映射   &#34; {[/ v2 / api-docs],methods = [GET],产生= [application / json ||   应用/ HAL + JSON]}&#34;上市   org.springframework.http.ResponseEntity   springfox.documentation.swagger2.web.Sw​​agger2Controller.getDocumentation(java.lang.String中,javax.servlet.http.HttpServletRequest)   2016-08-17 10:53:31.178 INFO 4037 --- [主要]   s.w.s.m.m.a.RequestMappingHandlerMapping:已映射   &#34; {[/配置/安全]}&#34;到   org.springframework.http.ResponseEntity   springfox.documentation.swagger.web.ApiResourceController.securityConfiguration()   2016-08-17 10:53:31.185 INFO 4037 --- [主要]   s.w.s.m.m.a.RequestMappingHandlerMapping:已映射   &#34; {[/招摇资源]}&#34;到   org.springframework.http.ResponseEntity&GT;   springfox.documentation.swagger.web.ApiResourceController.swaggerResources()   2016-08-17 10:53:31.188 INFO 4037 --- [主要]   s.w.s.m.m.a.RequestMappingHandlerMapping:已映射   &#34; {[/配置/ UI]}&#34;到   org.springframework.http.ResponseEntity   springfox.documentation.swagger.web.ApiResourceController.uiConfiguration()   2016-08-17 10:53:31.199 INFO 4037 --- [主要]   s.w.s.m.m.a.RequestMappingHandlerMapping:已映射   &#34; {[/错误],产生= [text / html的]}&#34;上市   org.springframework.web.servlet.ModelAndView   org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)   2016-08-17 10:53:31.204 INFO 4037 --- [主要]   s.w.s.m.m.a.RequestMappingHandlerMapping:Mapped&#34; {[/ error]}&#34;到   上市   org.springframework.http.ResponseEntity&GT;   org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)   线程中的异常&#34;线程-1&#34; java.lang.NoClassDefFoundError:   kafka / consumer / TopicFilter at   java.lang.Class.getDeclaredConstructors0(Native Method)at   java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)at at   java.lang.Class.getDeclaredConstructors(Class.java:2020)at   com.google.inject.assistedinject.FactoryProvider2.findMatchingConstructorInjectionPoint(FactoryProvider2.java:487)   在   com.google.inject.assistedinject.FactoryProvider2。(FactoryProvider2.java:286)   在   com.google.inject.assistedinject.FactoryModuleBuilder $ 1.configure(FactoryModuleBuilder.java:334)   在com.google.inject.AbstractModule.configure(AbstractModule.java:62)   在   com.google.inject.spi.Elements $ RecordingBinder.install(Elements.java:340)   在com.google.inject.AbstractModule.install(AbstractModule.java:122)   在   org.graylog2.plugin.inject.Graylog2Module.installTransport(Graylog2Module.java:84)   在   org.graylog2.plugin.inject.Graylog2Module.installTransport(Graylog2Module.java:74)   在   org.graylog2.inputs.transports.TransportsModule.configure(TransportsModule.java:36)   在com.google.inject.AbstractModule.configure(AbstractModule.java:62)   在   com.google.inject.spi.Elements $ RecordingBinder.install(Elements.java:340)   在com.google.inject.AbstractModule.install(AbstractModule.java:122)   在   org.graylog2.shared.bindings.MessageInputBindings.configure(MessageInputBindings.java:43)   在com.google.inject.AbstractModule.configure(AbstractModule.java:62)   在   com.google.inject.spi.Elements $ RecordingBinder.install(Elements.java:340)   在com.google.inject.spi.Elements.getElements(Elements.java:110)at   com.google.inject.internal.InjectorShell $ Builder.build(InjectorShell.java:138)   在   com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)   在com.google.inject.Guice.createInjector(Guice.java:96)at   org.graylog2.shared.bindings.Hk2GuiceBridgeJitInjector.create(Hk2GuiceBridgeJitInjector.java:60)   在   org.graylog2.shared.bindings.GuiceInjectorHolder.createInjector(GuiceInjectorHolder.java:32)   在   org.graylog2.bootstrap.CmdLineTool.setupInjector(CmdLineTool.java:379)   在org.graylog2.bootstrap.CmdLineTool.run(CmdLineTool.java:193)at   java.lang.Thread.run(Thread.java:745)引起:   java.lang.ClassNotFoundException:kafka.consumer.TopicFilter at   java.net.URLClassLoader.findClass(URLClassLoader.java:381)at   java.lang.ClassLoader.loadClass(ClassLoader.java:424)at   sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:331)at at   java.lang.ClassLoader.loadClass(ClassLoader.java:357)...还有27个   2016-08-17 10:53:31.643 INFO 4037 --- [主要]   o.s.w.s.handler.SimpleUrlHandlerMapping:映射的URL路径   [/swagger-ui.html]到[class]类型的处理程序   org.springframework.web.servlet.resource.ResourceHttpRequestHandler]   2016-08-17 10:53:31.644 INFO 4037 --- [主要]   o.s.w.s.handler.SimpleUrlHandlerMapping:映射的URL路径   [/ webjars / **]到[class]类型的处理程序   org.springframework.web.servlet.resource.ResourceHttpRequestHandler]   2016-08-17 10:53:31.762 INFO 4037 --- [主要]   s.w.s.m.m.a.RequestMappingHandlerAdapter:寻找   @ControllerAdvice:   org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7eac9008:   启动日期[Wed Aug 17 10:53:26 IST 2016];上下文层次结构的根   2016-08-17 10:53:31,777 WARN GraylogInstance:115:Graylog休息   界面尚未准备好,重新安排... 2016-08-17 10:53:32.330 INFO   4037 --- [主要] org.elasticsearch.node:[Monet St. Croix]   版本[2.2.2],pid [4037],build [fcc01dd / 2016-03-29T08:49:35Z]   2016-08-17 10:53:32.339 INFO 4037 --- [main] org.elasticsearch.node:   [Monet St. Croix]初始化...... 2016-08-17 10:53:32.361 INFO 4037   --- [主要] org.elasticsearch.plugins:[Monet St. Croix]模块[],插件[],网站[] 2016-08-17 10:53:32.423 INFO 4037 --- [主要]   org.elasticsearch.env:[Monet St. Croix]使用[1]数据路径,坐骑   [[/(/ dev / mapper / mint - vg-root)]],net usable_space [202.5gb],net   total_space [225gb],旋转? [可能],类型[ext4] 2016-08-17   10:53:32.430 INFO 4037 --- [主要] org.elasticsearch.env:[莫奈街   Croix]堆大小[848mb],压缩普通对象指针[true]   2016-08-17 10:53:32.432 WARN 4037 --- [main] org.elasticsearch.env:   [Monet St. Croix]弹性搜索的最大文件描述符[4096]   过程可能太低,考虑增加到至少[65536]   2016-08-17 10:53:32,780 WARN GraylogInstance:115:Graylog休息   界面尚未准备好,重新安排... 2016-08-17 10:53:33,782警告   GraylogInstance:115:Graylog休息界面尚未准备好,   重新安排... ****

0 个答案:

没有答案