我正在使用 fluentd 在 elasticsearch 中集中日志消息并使用 kibana 查看它们。当我查看日志消息时,同一秒内发生的消息是乱序的,@timestamp 中的毫秒数全为零
2015-01-13T11:54:01.000-06:00 DEBUG my message
如何流利地存储毫秒?
我正在使用 fluentd 在 elasticsearch 中集中日志消息并使用 kibana 查看它们。当我查看日志消息时,同一秒内发生的消息是乱序的,@timestamp 中的毫秒数全为零
2015-01-13T11:54:01.000-06:00 DEBUG my message
如何流利地存储毫秒?
fluentd 目前不支持亚秒级分辨率: https ://github.com/fluent/fluentd/issues/461
我通过使用 record_reformer 向所有日志消息添加一个新字段来解决此问题,以存储自纪元以来的纳秒
例如,如果您的 fluentd 有一些输入,如下所示:
#
# Syslog
#
<source>
type syslog
port 5140
bind localhost
tag syslog
</source>
#
# Tomcat log4j json output
#
<source>
type tail
path /home/foo/logs/catalina-json.out
pos_file /home/foo/logs/fluentd.pos
tag tomcat
format json
time_key @timestamp
time_format "%Y-%m-%dT%H:%M:%S.%L%Z"
</source>
然后将它们更改为如下所示并添加一个添加纳秒字段的record_reformer
#
# Syslog
#
<source>
type syslog
port 5140
bind localhost
tag cleanup.syslog
</source>
#
# Tomcat log4j json output
#
<source>
type tail
path /home/foo/logs/catalina-json.out
pos_file /home/foo/logs/fluentd.pos
tag cleanup.tomcat
format json
time_key @timestamp
time_format "%Y-%m-%dT%H:%M:%S.%L%Z"
</source>
<match cleanup.**>
type record_reformer
time_nano ${t = Time.now; ((t.to_i * 1000000000) + t.nsec).to_s}
tag ${tag_suffix[1]}
</match>
然后将 time_nano 字段添加到您的 kibana 仪表板并使用它而不是 @timestamp 进行排序,一切都会井井有条。