【问题标题】:Fluentd exclude filter works and doesn't workFluentd 排除过滤器有效且无效
【发布时间】:2020-03-31 14:36:19
【问题描述】:

我正在研究 fluentd 以将 Apache 日志发送到 http 输出。我部分成功了,但我不明白它似乎的 grep 过滤器。有些东西我放在那里,而另一些则没有,我真的看不出有什么不同,所以我很难过..

示例日志:

10.50.1.36 - - [31/Mar/2020:12:48:26 +0000] "GET /index.php?r=Hle/Create&ReturnUrl=/index.php?r=Hle/Admin HTTP/1.1" 200 34291 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"

我的 conf 文件过滤器如下所示:

<filter apache.access>
  @type grep
  <exclude>
    key path
    pattern /Create/
  </exclude>
</filter>

我的输入被相同的 apache.access 标记。上面的例子有效,但这不起作用:

<filter apache.access>
  @type grep
  <exclude>
    key method
    pattern /GET/
  </exclude>
</filter>

我希望这也能正常工作?传入的日志文件被解析为 apache,这是输出:

{"host":"10.50.1.36","method":"GET","path":"/index.php?r=Hle/Create&ReturnUrl=/index.php?r=Hle/Admin","code":200,"size":34291,"agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36","time":"31/Mar/2020:12:48:26 +0000"}

所以方法字段肯定包含 GET 值,但由于某种原因它没有被过滤掉?为什么有些东西有效而有些无效?我还尝试了字段路径中的其他选项,但到目前为止,似乎只有包含大写字母的字符串才会被过滤。例如,如果路径包含“create”这个词,我不能用 pattern /create/ 排除它?另一方面,如果它包含 Create 我可以用 pattern /Create/ 过滤掉它?

以防万一整个 conf 文件,也许可以解释它?

    ## read apache logs continuously and tags apache.access
     <source>
      @type tail
      @id input_tail
      <parse>
        @type apache2
        time_key "time"
        keep_time_key true
      </parse>
      path /var/log/apache2/httpd
      pos_file /var/log/td-agent/httpd-access.log.pos
      tag apache.access
    </source>


    <filter apache.access>
      @type grep
      <exclude>
        key method
        pattern /GET/
      </exclude>
    </filter>

    <filter apache.access>
      @type record_transformer
      <record>
        hostname "#{Socket.gethostname}"
      </record>
      remove_keys referer,user
    </filter>

<match apache.*>
  @type http

  endpoint http://localhost:9000
  open_timeout 2

  <format>
    @type json
  </format>
  <buffer>
    flush_interval 2s
  </buffer>
</match>

【问题讨论】:

    标签: filter grep fluentd td-agent


    【解决方案1】:

    您提供的配置对我来说很好用。 但是日志:

    10.50.1.36 - - [31/Mar/2020:12:48:26 +0000] "GET /index.php?r=Hle/Create&ReturnUrl=/index.php?r=Hle/Admin HTTP/1.1" 200 34291 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"
    

    根据doc,似乎缺少referer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-27
      • 2013-04-09
      • 2013-04-25
      • 2011-08-02
      • 2013-06-17
      • 2012-09-21
      • 1970-01-01
      • 2013-07-24
      相关资源
      最近更新 更多