1

我正在设置一个 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 文档中。

我会感谢一些帮助

4

1 回答 1

0

实际上,您需要使用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>
于 2014-07-31T14:43:36.477 回答