LogstashTcpSocketAppender未将日志发送到Logstash

时间:2017-06-11 06:56:29

标签: java spring spring-boot docker-compose elastic-stack

我在Spring Boot应用程序中使用Docker ELK堆栈。所有三个组件分别在http://192.168.99.100:5601/http://192.168.99.100:9200/和192.168.99.100:5000处启动并运行。

我的logback-spring.xml如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
    <keepAliveDuration>5 minutes</keepAliveDuration>
    <reconnectionDelay>10 second</reconnectionDelay>
    <waitStrategyType>sleeping</waitStrategyType>
    <destination>192.168.99.100:5000</destination>
    <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
        <providers>
            <mdc/> <!-- MDC variables on the Thread will be written as JSON fields-->
            <context/> <!--Outputs entries from logback's context -->
            <logLevel/>
            <loggerName/>
            <pattern>
                    {
                    "timestamp": "%date{\"yyyy-MM-dd'T'HH:mm:ss,SSSXXX\", UTC}",
                    "level": "%level",
                    "logger": "%logger",
                    "message": "%message",
                    "logstashMarkers": "%marker"
                    }
                </pattern>
            <threadName/>
            <message/>
            <logstashMarkers/> <!-- Useful so we can add extra information for specific log lines as Markers-->
            <arguments/> <!--or through StructuredArguments-->
           <stackTrace>
                <fieldName>stackTrace</fieldName>
                <throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
                    <exclude>net\.sf\.cglib\..*</exclude>
                    <maxDepthPerThrowable>30</maxDepthPerThrowable>
                    <rootCauseFirst>true</rootCauseFirst>
                </throwableConverter>
            </stackTrace>
        </providers>
    </encoder>
</appender>

<root level="INFO">
    <appender-ref ref="stash"/>
</root>

问题是我无法在Kibana中看到我的日志,我怀疑LogstashTcpSocketAppender是不是将日志发送到Logstash。有没有办法验证LogstashTcpSocketAppender是否正在向Logstash发送日志?

1 个答案:

答案 0 :(得分:1)

- 检查消息是否发送到elasticsearsh:  192.168.99.100:9200/_search

- 检查索引是否已创建:  192.168.99.100:9200/_cat/indices

- 实际上,如果你想看到你应该在kibana的索引中创建的结果(与elasticsearh中创建的名称/模式相同):

enter image description here

并通过修改时间来验证kibana:

enter image description here