【问题标题】:FluentD How to ignore pattern not match log not to forward to endpointFluentD如何忽略模式不匹配日志不转发到端点
【发布时间】:2021-12-02 07:27:08
【问题描述】:

我们有一个要求,我们只需要将特定的字符串日志转发到 kibana 端点/控制台。目前我们正在获取未找到匹配字符串的模式不匹配行。如何忽略那些不发送到转发器的日志,只发送匹配日志。

<source>
  @type tail
  path session.txt
  pos_file session.txt.pos
  tag sessionlog
  <parse>
    @type regexp
    expression ^\<#\>\s+(?<time>\w+/\w+/\w+\s+[:0-9]+)\s+(?<hostname>[-0-9A-Z]+)\s+(?<message>.*Clip.*)$/
  </parse>
</source>

<match sessionlog>
  @type stdout
</match>
<#> 2019/11/16 13:56:33 ABC-Hostanme 278424 Dispatcher_1 Msg [Unit1] error emitted: '404'from session start: 2021-11-16T08:54:01
<#> 2019/11/16 13:56:33 ABC-Hostanme 278424 Dispatcher_1 Msg [Unit1] clip result: a1=0, a2=217, a3=152475, a4=148692

结果:

[warn]: #0 pattern not match: <#> 2019/11/16 13:56:33 ABC-Hostanme 278424 Dispatcher_1 Msg [Unit1] error emitted: '404'from session start: 2021-11-16T08:54:01
sessionlog: {"hostname":"DESKTOP-3JOOBVV","message":"278424 Dispatcher_1 Msg [Unit1] clip result: a1=0, a2=217, a3=152475, a4=148692"}

我们只想获取匹配的模式日志。

【问题讨论】:

    标签: fluentd


    【解决方案1】:

    @sunshine,如果正则表达式解析器无法从日志中提取匹配项,它将发出该错误。因此,它建议通过正则表达式解析器的所有日志行都可以由表达式匹配。我建议您在正则表达式解析器之前使用 grep 过滤器,以避免来自 fluentd 的那些“模式不匹配”​​日志。

    我在下面粘贴了一个示例,但您也可以在 grep 过滤器中使用 &lt;exclude&gt; 块。有关更多信息和示例,请参见此处:https://docs.fluentd.org/filter/grep

    <source>
      @type tail
       path session.txt
       pos_file session.txt.pos
       tag sessionlog
    </source>
    
    <filter sessionlog>
      @type grep
      <regexp>
        key message
        pattern /INCLUDE_PATTERN_HERE/
      </regexp>
    </filter>
    
    <filter sessionlog>
      @type parser
      key_name message
      reserve_data true
      <parse>
        @type regexp
        expression ^\<#\>\s+(?<time>\w+/\w+/\w+\s+[:0-9]+)\s+(?<hostname>[-0-9A-Z]+)\s+(?<message>.*Clip.*)$/
      </parse>
    </filter>
    
    <match sessionlog>
      @type stdout
    </match>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-02
      • 2015-04-03
      • 1970-01-01
      • 2021-09-16
      • 2016-05-21
      • 1970-01-01
      • 2015-12-17
      • 1970-01-01
      相关资源
      最近更新 更多