在使用fluentd+elasticsearch的配置中,如何启用毫秒级时间戳的方法

以下是截至2014年年底的信息。有关如何使用fluentd-0.12.x,请查看追加备注2。

在中国,只需要一种选择,将以下内容以中文母语方式改写:

背景

我想在Fluentd+Elasticsearch+Kibana的架构中处理毫秒级的时间戳。

流畅的日志转发器

内部记录中的时间字段是使用Unix时间戳表示的。因此,它不支持毫秒级别的时间戳作为标准格式。(有人正在考虑将内部数据转换为浮点数的方法。)

流畅的插件-弹性搜索

    • fluentdの内部で渡されるtimeを@timestampに変換してelasticsearchへ渡している。

 

    • レコードに@timestampが予め用意されている場合はそれをelasticsearchへ投げる。

 

    この段階で@timestampがミリ秒のデータを含み、適切なフォーマット”%Y-%m-%dT%H:%M:%S.%L%z”の場合、elasticsearchに適切な状態で保存されKibanaで取り扱い可能となる。

实施

我准备了以下两种方式。

    1. 以下为其中一个汉语翻译选项:

修复版(分支)的 fluent-plugin-elasticsearch https://github.com/shivaken/fluent-plugin-elasticsearch

用于 fluentd 的过滤器插件https://github.com/shivaken/fluent-plugin-better-timestamp

1. 只需在记录中准备msec,即可使其运行。
2. 作为过滤器,需要添加以下设置。

 <source>
  type tail
  format
  format /^(?<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).(?<msec>\d{3}) .....
  ...
  tag log
 </source>
 <match log>
  type better_timestamp
  tag log.with_msec
 </match>
 <match tag log.with_msec>
  type elasticsearch
  ...
 </match

根据情况选择是通过Git使用第一个选项还是安装Gem并添加一个过滤器。

关于1,我们计划通过另外的问题进行合并到主体上。也许最好是在问题上发表意见,然后提出拉取请求。

追加备注:已发出Pull请求。
https://github.com/uken/fluent-plugin-elasticsearch/pull/82

补充2:有关在fluentd 0.12.x版本中的配置方法已经提到了。
https://github.com/uken/fluent-plugin-elasticsearch/issues/39#issuecomment-171642223

bannerAds