是否可以使用 fluentd 监控整个目录?

Is it possible to monitor a whole directory with fluentd?

我想将日志转发设置为部署过程的一部分。 activity 的机器会有所不同,但它们都会记录到特定的地方(特别是 /var/log)。

是否可以配置 fluentd 以便它监视整个目录?(包括在活动时选择弹出文件的能力)

我知道 in_tail 可以对给定的指定文件执行此操作,但文档没有提到整个目录。


有一个理想exact duplicate of this question from 2014 which points to the tail_ex plugin。不幸的是它的描述提到

Deprecated: Fluentd has the features of this plugin since 0.10.45. So, the plugin no longer maintained

我仍然找不到提到的功能。

使用 Fluentd 的 in_tail 插件中的通配符支持,这绝对是可能的。在 path 部分中,您将指定 /var/log/* 目录,Fluentd 将自动跳过不可读的文件。

另外,如果你往该目录写入新文件,Fluentd会根据配置项https://docs.fluentd.org/v0.12/articles/in_tail#refreshinterval

定期扫描

一些注意事项:如果您使用 Fluentd、td-agent 的 Treasure Data's 打包版本,那么您需要确保您想要跟踪的文件可被配置为 td-agent 的用户读取该安装的一部分。

最后,如果您需要安全地阅读这些文件,您可以考虑 Treasure Data's Enterprise Fluentd offering