使用来自相同来源的流利标签来解析不同格式?

问题描述

我在docker-compose文件中使用了流利的文件,我希望它在其中解析apache容器以及其他具有自定义格式的容器的日志输出

为了区分格式,我打算像这样在docker-compose中设置标签

      logging:
        driver: "fluentd"
        options:
          tag: "apache2"

因此,fluentd应该能够根据标签使用不同的格式。但是我该如何配置fluentd来做到这一点?

documentation说,应该将其放在源代码部分中(我不能这样做,因为我需要两种不同的格式):

  <parse>
    @type apache2
  </parse>

我最基本的source看起来像这样:

<source>
  @type forward                                                                                         
  port 24224
  bind 0.0.0.0
</source>

是否可以使用流线型路由对来自同一source标签不同的数据使用两种不同的格式?

解决方法

是的,有可能:

# 1. Omit parsing at the source
<source>
  @type forward                                                                                         
  port 24224
  bind 0.0.0.0
</source>

# 2. Write a dedicated filter for each format you want
<filter docker.apache2> # Check your exact produced tag,depends of versions. Just guessing here.
  @type parser
  key_name log
  <parse>
    @type apache2
  </parse>
</filter>

<filter docker.backend>
  @type parser
  key_name log
  <parse>
    @type json
  </parse>
</filter>

# 3. Match and store all
<match **>
  @type s3 
  ...
</match>