首页 > 解决方案 > 如何在fluentd的输出路径中使用标签?

问题描述

我正在尝试使用 fluentd 复制一堆日志文件。所有日志文件都需要写入相同的目标目录。

      @type tail
      @id container-input
      format none
      path "/var/log/containers/plugin*.log"
# This path would match multiple files that I want to log
      pos_file "/var/log/plugin.log.pos"
      refresh_interval 5
      rotate_wait 5
      read_from_head "true"
      tag plugin.*
    </source>
    <filter plugin.**>
      @type record_transformer
      <record>
        filename ${tag_suffix[-2]}
      </record>
    </filter>
    <match plugin**>
      @type file
      path /destlogs/plugin.log
    </match>

我想要的是在输出路径中的某处使用文件名,例如

path /destlogs/plugin-${filename}.log

但是,当我使用这样的配置时,fluentd 不会选择文件名标签作为变量,而是按原样创建路径。

如何在输出路径中使用标签作为变量?

标签: fluentd

解决方案


这里的问题是版本。v0.12 似乎不支持匹配部分中的标签,而 v1.0 支持。我使用的是流利的图像 fluent/fluentd-kubernetes-daemonset:elasticsearch,我意识到它使用的是旧的流利版本。更新它以 fluent/fluentd-kubernetes-daemonset:v1-debian-elasticsearch解决问题。


推荐阅读