Filebeat将mysql-slow.log的几行合并为一行

我正在尝试使用Filebeat Logstash和Elasticsearch分析mysql-slow.log。我在mysql-slow.log文件中有如下消息:

# Time: 2019-11-08T20:02:05.474508Z
# User@Host: user[user] @ localhost []  Id:     2
# Query_time: 0.000716  Lock_time: 0.000223 Rows_sent: 2  Rows_examined: 2
SET timestamp=1573243325;
select * from Persons;

首先,我尝试使Filebeat将这行日志消息以5行的形式发送给elasticsearch,但将它们全部一起发送到一行。

我在filebeat.yml中设置了多行输入

multiline.pattern = `^\#`
multiline.negate = true
multiline.match = after

不幸的是,它不起作用,elasticsearch分别接收行

  1. 消息->#时间:2019-11-08T20:02:05.474508Z
  2. 消息->#User @ Host:user [user] @ localhost [] ID:2 等等...

我想在一封邮件中以以下格式接收它:

# Time: 2019-11-08T20:02:05.474508Z # User@Host: user[user] @ localhost []  Id:     2 # Query_time: 0.000716  Lock_time: 0.000223 Rows_sent: 2  Rows_examined: 2 SET timestamp=1573243325; select * from Persons;
owenlzhao 回答:Filebeat将mysql-slow.log的几行合并为一行

您的多行模式是错误的,它将与以EKEventEditViewController开头的任何行匹配,因此示例中的前三行将是filebeat / logstash的事件。

您需要更改多行模式以仅匹配事件的第一行,即以#开头的行。

以下filebeat配置适用于我的测试。

# Time

logstash管道简单监听filebeat.inputs: - type: log enabled: true paths: - /opt/data/stackoverflow/*.log multiline.pattern: '^\#[[:space:]]Time' multiline.negate: true multiline.match: after output.logstash: hosts: ["elk:5044"] 并输出到elasticsearch,结果如下。

enter image description here

如您所见,所有文件行都被索引为Elasticsearch上的单个事件。

本文链接:https://www.f2er.com/3135319.html

大家都在问