【问题标题】:fluentd: one source for several filters and matchesfluentd:多个过滤器和匹配项的一个来源
【发布时间】:2019-05-26 09:42:28
【问题描述】:

我有来源:

<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


    【解决方案1】:

    您可以尝试使用插件copyrelabel 来实现这一点。示例配置如下所示。

    //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>
    

    这篇Routing 示例文章通过重写标签等方式提供了更多方法,但对我来说,我喜欢使用标签,上面看起来很简单。

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

    【讨论】:

      【解决方案2】:

      我用rewrite_tag_filter 做到了。

      首先我通过TCP创建了source

      <source>
        @type tcp
        tag tcp.price-parser
        port 20001
        bind 0.0.0.0
        <parse>
          @type json
        </parse>
      </source>
      

      第二步是匹配tcp.price-parcer标签并用JSON数据重写标签

      <match tcp.price-parser>
        @type rewrite_tag_filter
        <rule>
          key tag
          pattern /(info|error)/
          tag $1.${tag}
        </rule>
      </match>
      

      它的重要集合rule 并匹配它。如果它不匹配,流利的不要走得更远。 所以我的keytag。此密钥来自 JSON。例如 JSON:

      {"tag":"info","message":"My first message"}

      并且规则 pattern 正则表达式 JSON tag 键与 /(info|error)/ 值。如果找到infoerror 我们可以重写fluentd tag。 所以tag $1.${tag} 等于info.tcp.price-parsererror.tcp.price-parser

      现在你可以匹配重写标签了

      <match info.tcp.price-parser>
        @type slack
        token xoxb-***
        channel price-parser
        username la
        icon_emoji :ghost:
        message "%s"
        message_keys message
        flush_interval 5s
      </match>
      

      【讨论】:

        猜你喜欢
        • 2023-03-13
        • 2021-07-29
        • 2016-10-23
        • 1970-01-01
        • 2022-09-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多