首页 > 解决方案 > fluentd:多个过滤器和匹配的一个来源

问题描述

我有来源:

<source>
    @type tail
    tag service
    path /tmp/l.log
    format json
    read_from_head true
</source>

我想在它上面做几个过滤器,然后match输出几个:

<source>
    @type tail
    tag service.pi2
    path /tmp/out.log
    format json
    read_from_head true
</source>

<source>
    @type tail
    tag service.data
    path /tmp/out.log
    format json
    read_from_head true
</source>

<filter service.data>
   # some filtering
</filter>

<filter service.pi2>
   # some filtering
</filter>

<match service.data>
  @type file
  path /tmp/out/data
</match>

<match service.pi2>
  @type file
  path /tmp/out/pi
</match>

到目前为止,为了使一切正常,我必须source使用不同的标签进行复制。我可以让它从一个源定义中工作吗?

标签: fluentd

解决方案


您可以尝试使用插件复制重新标记来实现此目的。示例配置如下所示。

//One Source
<source>
    @type tail
    tag service
    path /tmp/l.log
    format json
    read_from_head true
</source>

//Now Copy Source Events to 2 Labels
<match service>
  @type copy
  <store>
    @type relabel
    @label @data
  </store>
  <store>
    @type relabel
    @label @pi2
  </store>
</match>

//@data Label, you can perform desired filter and output file
<label @data>
  <filter service>
    ...
  </filter>
  <match service>
    @type file
    path /tmp/out/data
  </match>
</label>

//@pi2 Label, you can perform desired filter and output file
<label @pi2>
  <filter service>
    ...
  </filter>
  <match service>
    @type file
   path /tmp/out/pi
  </match>
</label>

这篇路由示例文章有更多的方法可以通过重写标签等来做到这一点,但对我来说,我喜欢使用标签,上面看起来很简单。

我已经测试了上面的配置,它工作正常。让我知道你的想法 :)。


推荐阅读