ELK+Filebeat+Kafka,SpringBoot异常日志收集

该博客介绍了如何使用ELK Stack(Elasticsearch, Logstash, Kibana)配合Filebeat和Kafka来收集和格式化SpringBoot应用的日志。通过logback-spring.xml配置SpringBoot日志输出格式,Filebeat配置多行日志合并,以及Logstash使用grok过滤器将日志转换为JSON格式,最终将日志发送到Elasticsearch进行分析。此外,还提供了Logstash配置文件示例和Kibana的GrokDebugger工具来验证日志格式化效果。

概述

FileBeat + Kafka + ELK,收集SpringBoot项目的日志输出,有几个地方需要注意:

  • 项目日志输出格式化
  • Filebeat将多行日志汇集成一行
  • Logstash将项目日志格式化为json

SpringBoot项目日志输出格式化

logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <if condition='isDefined("catalina.home")'>
        <then>
            <property name="log_path" value="${catalina.home}"/>
        </then>
        <else>
            <property name="log_path" value="./target"/>
        </else>
    </if>
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>[%d] [%p] [%t] [%c] - %m%n</pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
...
    <root level="info">
        <appender-ref ref="console"/>
    </root>

</configuration>

xml配置文件中,[%d] [%p] [%t] [%c] - %m%n 确定了日志的规则,实际的日志输出格式如下:

[2021-04-25 09:50:58,255] [INFO] [RMI TCP Connection(23)-10.10.20.248] [org.springframework.web.servlet.DispatcherServlet] - Initializing Servlet 'dispatcherServlet'
[2021-04-25 09:50:58,324] [INFO] [RMI TCP Connection(23)-10.10.20.248] [org.springframework.web.servlet.DispatcherServlet] - Completed initialization in 69 ms
[2021-04-25 09:50:58,565] [WARN] [RMI TCP Connection(24)-10.10.20.248] [org.springframework.boot.actuate.elasticsearch.ElasticsearchHealthIndicator] - Elasticsearch health check failed
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{
   
   #transport#-1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值