ELK+Filebeat+Kafka,SpringBoot异常日志收集
概述
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

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

被折叠的 条评论
为什么被折叠?



