【问题标题】:pass the file name to the match plugin将文件名传递给匹配插​​件
【发布时间】:2014-07-30 16:06:57
【问题描述】:

我正在设置一个 fluentd / elasticsearch / kibana 堆栈,我想在文档中注册我收到事件的文件名。

这是我的配置:

<source>
  type tail_ex
  path /tmp/data/access
  pos_file /tmp/data/log.pos
  format /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[\
^\"]*)" "(?<agent>[^\"]*)")?/
  time_format %d/%b/%Y:%H:%M:%S %z
  tag front.nginx.access
  refresh_interval 1800
</source>

目前,我明白了:

{
    _index: logstash-2014.07.21
    _type: nginx
    _id: 0Wct7JCkT3qu7G79-cH4uw
    _version: 1
    _score: 1
    _source: {
        host: X.X.X.X
        user: -
        method: GET
        path: /acl/yyy/2/service/1/sss?index=100&num=100
        code: 200
        size: 153750
        referer: -
        agent: -
        @timestamp: 2014-07-21T03:00:14+02:00
    }
}

我想拥有该领域:

路径:/tmp/data/access

在我的 ES 文档中。

我会感谢一些帮助

【问题讨论】:

    标签: elasticsearch fluentd


    【解决方案1】:

    其实你需要使用tail_ex插件,并用文件名重命名标签

    <source>
      type tail_ex
      log_level fatal
      path /tmp/data/FILERS/cda_logs_sas1/*/*/logs/access*, /tmp/data/FILERS/cda_logs_sas1/*/*/logs/archives/access.*
      pos_file /tmp/data/log.pos
      format /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?/ 
      time_format %d/%b/%Y:%H:%M:%S %z 
      tag front.nginx.access.*
    </source>
    

    然后用 record_reformer 捕获标签并提取文件名并用它创建一个新密钥 (log_file ${tag_suffix[3]})

    <match front.nginx.access.**>
      type record_reformer
      log_level fatal
      enable_ruby false
      <record>
        log_file ${tag_suffix[3]}
      </record>
      tag filtered.front.nginx.access
    </match>
    

    然后查看结果

    <match filtered.front.nginx.access>
        type stdout
    </match>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-08
      • 2019-03-18
      相关资源
      最近更新 更多