设置 document_type 登录 filebeat 停止 filebeat 重启

Setting document_type of log in filebeat stops filebeat restarting

我正在尝试通过 filebeat 导入服务器上的自定义日志,并将其发送到 logstash 以便在我的 ELK 堆栈中使用。

我已将其设置为正常工作,目前运行良好。

但是,我希望为这个特定的日志添加一个 logstash 过滤器,因此决定为这个日志添加一个 document_type 字段,以允许我在 logstash 中基于它进行过滤。

我是这样做的:

filebeat.prospectors:
- input_type: log
  paths:
    - /var/log/apache2/access.log
  document_type: apache-access

- input_type: log
  paths:
    - /var/www/webapp/storage/logs/laravel.log

- input_type: log
  paths:
    - /opt/myservice/server/server.log
    document_type: myservice

我已将 document_type: myservice 添加到 myservice 的日志中,并且相信我已根据文档 here 这样做了。此外,它与我对 apache 访问日志所做的相同。

然而,当我重新启动 filebeat 时,它不会再次启动备份。我已经尝试查看 filebeat 的日志 - 但是其中似乎没有任何关于它无法启动的原因。

如果我注释掉 document_type: myservice,像这样 #document_type: myservice 然后重新启动 filebeat,它会正确启动,这意味着它一定与该行有关?

问题:

我是不是做错了什么?

除了使用 if [type] == "myservice" 之外,是否有其他方法可以将我的 logstash 过滤器应用于此日志?

使用 document_type 是在 Logstash 中应用条件的好方法。另一种方法是在 Filebeat 中应用 tags or fields

您的配置问题在于您添加的 document_type: myservice 的缩进。请注意缩进与 document_type: apache-access 有何不同。 document_type 字段应与 pathsinput_type 处于同一级别,因为它们都是探矿者选项。

您可以使用 filebeat.sh -c /etc/filebeat/filebeat.yml -e -configtest 测试您的配置文件。

您还可以通过 http://www.yamllint.com 等工具 运行 您的配置,只是为了检查它是否是有效的 YAML。