【问题标题】:Fluentd Configuration File, get filename in <source> and pass it to <match> as a tagFluentd 配置文件,获取 <source> 中的文件名并将其作为标记传递给 <match>
【发布时间】:2017-07-28 01:54:36
【问题描述】:

我正在尝试为 fluentd + fluentd-s3-plugin 编写一个干净的配置文件并将其用于许多文件。

我想避免为每个文件复制和粘贴每个&lt;source&gt; 和每个&lt;match&gt;,所以我想让它有点动态。到目前为止我所拥有的:

  <source>
    @type tail
    path /var/www/blabla/blabla/log/production.log
    pos_file /var/www/blabla/blabla/log/production.log.pos
    tag production-log
    format /(?<time>.*)/
  </source>


  <match production-log>
    @type s3

      s3_bucket xxxx
      s3_region xxxx

      path "staging/%Y/%m/%d/#{Socket.gethostname}/"
      s3_object_key_format "%{path}productionlog-%{time_slice}-#{Socket.gethostname}-%{index}.%{file_extension}"

      # if you want to use ${tag} or %Y/%m/%d/ like syntax in path / s3_object_key_format,
      # need to specify tag for ${tag} and time for %Y/%m/%d in <buffer> argument.
      <buffer tag,time>
        @type file
        tag ${tag}
        path /var/www/blabla/blabla/log/buffer/
        timekey 3600 # (default 3600) 1 hour partition
        timekey_wait 1m
        timekey_use_utc true # use utc

      </buffer>
      <format>
        @type json
      </format>
  </match>

如您所见,我多次使用生产日志,所以我的问题是 2:

如何使用tag中的文件名?

如何在s3_object_key_format 中使用这个传递的标签? (我知道有注释说明但我不明白)

【问题讨论】:

    标签: config fluentd


    【解决方案1】:

    您是否能够解决上述问题?您确实需要将标签字段传递给缓冲区,但不需要在缓冲区内使用。

    这是我的工作配置。希望这会有所帮助,如果它还没有解决的话。我的不同来源为标签字段发送不同的值,在 S3 下,我按标签字段创建单独的文件夹并将对象放在它们下面。

    所以它会像(app1 和 app2 是标签)

    mybucket-->topPrefix-->app1-->app.log

    mybucket-->topPrefix-->app2-->app.log

    <match>
      @type s3
    
      s3_bucket "mybucket"
      path "topPrefix/${tag}"
      s3_object_key_format "%{path}/%{time_slice}_#{Socket.gethostname}_%{index}.%{file_extension}"
      include_time_key true
      time_format "%Y-%m-%dT%H:%M:%S.%L"
    
      <buffer tag,time>
        @type file
        path /fluentd/buffer/s3
        timekey_wait 1m
        timekey 1m
        chunk_limit_size 64m
      </buffer>
      <format>
        @type json
      </format>
      time_slice_format %Y%m%d%H%M
    </match>
    

    【讨论】:

    • 感谢您的回答。不幸的是,我无法让它工作,而且时间紧迫,所以我最终复制粘贴了 2 次配置。这些天我可能会回来看看你的解决方案!
    猜你喜欢
    • 1970-01-01
    • 2013-03-01
    • 2012-03-17
    • 2021-02-10
    • 2017-06-09
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 2022-12-01
    相关资源
    最近更新 更多