springboot+elk+docker實戰

weixin_33766168發表於2016-05-18

logback-logstash配置

  • pom依賴

<!-- Logstash encoder -->
        <dependency>
            <groupId>net.logstash.logback</groupId>
            <artifactId>logstash-logback-encoder</artifactId>
            <version>4.4</version>
        </dependency>
  • logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are  by default assigned the type
             ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="logstash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <remoteHost>logstash</remoteHost>
        <port>5000</port>
        <!-- encoder is required -->
        <encoder class="net.logstash.logback.encoder.LogstashEncoder" />
    </appender>

    <root level="info">
        <appender-ref ref="logstash" />
        <appender-ref ref="STDOUT" />
    </root>

    <jmxConfigurator/>
</configuration>

logstash.conf

input {
    tcp {
        port => 5000
        type => "springboot"
    }
}

## Add your filters here

output {
    elasticsearch {
        hosts => "elasticsearch:9200"
        index => "springboot"
    }
}

kibana

http://192.168.99.100:5601/app/kibana
clipboard.png