当前位置:网站首页>ELK + filebeat日志解析、日志入库优化 、logstash过滤器配置属性
ELK + filebeat日志解析、日志入库优化 、logstash过滤器配置属性
2022-06-25 06:39:00 【fate急速出击】
前言
前段时间不是搭建了一套ELK日志分析系统嘛,然后日志是通过beats读取落地日志,推送给logstash,然后再由logstash推送到elasticsearch索引库,最后通过kibana可视化工具进行日志的分析查看,搭建过程详见Springboot/Springcloud整合ELK平台,(Filebeat方式)日志采集及管理(Elasticsearch+Logstash+Filebeat+Kibana)
下面这张图是kibana展示的结果,这里我们发现有好多无用和重复的字段,并且我的日志字段还得展开才能看到,这部分肯定可以优化。然后我的Springboot/Springcloud整合ELK平台,(Filebeat方式)日志采集及管理(Elasticsearch+Logstash+Filebeat+Kibana)这篇文章评论区也有个小伙伴问我beats可以直接推送到elasticsearch,为什么还要通过logstash?
在这个小伙伴评论之前,我就已经优化好了日志, 这篇文章记录一下我解析优化日志的过程!
优化结果

实现
首先,我们知道logstash有很多的过滤插件
| 插件 | 说明 |
|---|---|
| date | 日期解析 |
| grok | 正则匹配解析 |
| dissect | 分隔符解析 |
| mutate | 对字段作处理,比如重命名、删除、替换 |
| json | 按照json解析字段内容到指定字段中 |
| geoip | 增加地理位置数据 |
| ruby | 利用ruby代码来动态修改Logstash Event |
这里我参考了这两篇文章的示例,之后对我的logstash日志进行修改
Logstash filter 的使用
logstash配置详解
- 这是我的输出日志
2022-06-10 11:00:47.974 ERROR [main] com.alibaba.nacos.client.config.http.ServerHttpAgent : [NACOS SocketTimeoutException httpGet] currentServerAddr:http://127.0.0.1:8848, err : connect timed out
- 这是我log4j定义的格式,这里我在logstash配置文件中根据这个格式进行解析,日志整合详见什么是日志门面? SpringBoot整合log4j2 ,日志落地
# log4j2
%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight{%-5level} [%thread] %style{%logger{36}}{cyan} : %msg%n
# logstash配置中解析
%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:level} %{JAVALOGMESSAGE:thread} %{JAVALOGMESSAGE:style} : %{JAVALOGMESSAGE:msg}
logstash
input {
beats {
port => 5044
type => "logs"
}
tcp {
mode => "server"
host => "127.0.0.1"
port => 4560
codec => json_lines
}
}
filter {
//解析日志
grok{
match => {
"message" => "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:level} %{JAVALOGMESSAGE:thread} %{JAVALOGMESSAGE:style} : %{JAVALOGMESSAGE:msg}" }
}
//将入库时间替换成我们日志中的时间
date {
match => [ "timestamp" , "yyyy-MM-dd HH:mm:ss,S", "ISO8601" ]
}
//删除多余字段
mutate {
remove_field => "agent"
remove_field => "ecs"
remove_field => "@version"
remove_field => "host"
remove_field => "path"
remove_field => "log"
remove_field => "message"
}
}
output {
elasticsearch {
hosts => ["http://127.0.0.1:9200"]
user => "elastic"
passwrod => "123456"
index => "%{[fields][servicename]}-%{+yyyy.MM.dd}"
}
}
filebeat
添加配置
multiline:
pattern: ‘^\s*(\d{4}|\d{2})-(\d{2}|[a-zA-Z]{3})-(\d{2}|\d{4})’ 符合java日志换行规则
filebeat.inputs:
- type: log
enabled: true
paths:
- E:\ideaProject\SpringCloudAlibaba2022\logs\order-service\info.log
#- c:\programdata\elasticsearch\logs\*
fields:
servicename: order-service
multiline:
pattern: '^\s*(\d{4}|\d{2})\-(\d{2}|[a-zA-Z]{3})\-(\d{2}|\d{4})'
negate: true
match: after
timeout: 5s
- type: log
enabled: true
paths:
- E:\ideaProject\SpringCloudAlibaba2022\logs\user-service\info.log
#- c:\programdata\elasticsearch\logs\*
fields:
servicename: user-service
multiline:
pattern: '^\s*(\d{4}|\d{2})\-(\d{2}|[a-zA-Z]{3})\-(\d{2}|\d{4})'
negate: true
match: after
timeout: 5s
完成以上这些配置修改之后,重启filebeat、logstash
有任何问题随时私信联系!
原创不易,如果有帮助到你的话点个赞再走吧!感谢!
边栏推荐
- Ca-is1200u current detection isolation amplifier has been delivered in batch
- My debut is finished!
- 稳压二极管的原理,它有什么作用?
- Several good weather plug-ins
- 威迈斯新能源冲刺科创板:年营收17亿 应收账款账面价值近4亿
- Don't you know the evolution process and principle of such a comprehensive redis cluster model?
- Large funds support ecological construction, and Plato farm builds a real meta universe with Dao as its governance
- [batch dos-cmd command - summary and summary] - CMD extended command and function (CMD /e:on, CMD /e:off)
- Weimeisi new energy rushes to the scientific innovation board: the annual revenue is 1.7 billion, and the book value of accounts receivable is nearly 400million
- Chuantu microelectronics breaks through the high-end isolator analog chip market with ca-is3062w
猜你喜欢

Chuantu microelectronics breaks through the high-end isolator analog chip market with ca-is3062w

太上老君的炼丹炉之分布式 Quorum NWR

Sichuan earth microelectronics 8-channel isolated digital input receiver

How is the network connected?

My debut is finished!

Research on 3D model retrieval method based on two channel attention residual network - Zhou Jie - paper notes

MySQL facet 01

Explain distributed raft with dynamic diagram

What common APIs are involved in thread state changes

LeetCode 每日一题——515. 在每个树行中找最大值
随机推荐
Notes: [open class] neural network and deep learning -- tensorflow2.0 actual combat [Chinese course]
Google extender address
Sichuan earth microelectronics 8-channel isolated digital input receiver
【批处理DOS-CMD命令-汇总和小结】-外部命令-cmd下载命令、抓包命令(wget)
[batch dos-cmd command - summary and summary] - external command -cmd download command and packet capture command (WGet)
[introduction to UVM== > episode_9] ~ register model, integration of register model, general methods of register model, application scenarios of register model
Sqlmap advanced use – cookies
How do I create a guid in excel- How to create a GUID in Excel?
JMeter introduction practice ----- use of global variables and local variables
【LeetCode】two num·两数之和
Harmony food menu interface
How comfortable it is to use Taijiquan to talk about distributed theory!
MySQL face Scripture eight part essay
Chuantuwei ca-is3720lw alternative material No. iso7820fdw
The principle of Zener diode, what is its function?
Redis learning notes
Common functions of OrCAD schematic
Chuantu microelectronics breaks through the high-end isolator analog chip market with ca-is3062w
[Yu Yue education] engineering testing technology reference of Wenhua University
Display purchase Summary - Dell 2705qm BenQ pd2700u

