elasticsearch fluentd会丢失毫秒,现在日志消息在elasticsearch中无序存储,elasticsearch,kibana,fluentd,elasticsearch,Kibana,Fluentd" /> elasticsearch fluentd会丢失毫秒,现在日志消息在elasticsearch中无序存储,elasticsearch,kibana,fluentd,elasticsearch,Kibana,Fluentd" />

elasticsearch fluentd会丢失毫秒,现在日志消息在elasticsearch中无序存储

elasticsearch fluentd会丢失毫秒,现在日志消息在elasticsearch中无序存储,elasticsearch,kibana,fluentd,elasticsearch,Kibana,Fluentd,我正在使用fluentd集中elasticsearch中的日志消息,并使用kibana查看它们。当我查看日志消息时,在同一秒内发生的消息是无序的,@timestamp中的毫秒都是零 2015-01-13T11:54:01.000-06:00 DEBUG my message 如何让fluentd存储毫秒?fluentd当前不支持亚秒分辨率: 我通过使用record_reformer在所有日志消息中添加一个新字段来解决这个问题,以存储自epoch以来的纳秒 例如,如果您的fluentd

我正在使用fluentd集中elasticsearch中的日志消息,并使用kibana查看它们。当我查看日志消息时,在同一秒内发生的消息是无序的,@timestamp中的毫秒都是零

2015-01-13T11:54:01.000-06:00   DEBUG   my message

如何让fluentd存储毫秒?

fluentd当前不支持亚秒分辨率:

我通过使用record_reformer在所有日志消息中添加一个新字段来解决这个问题,以存储自epoch以来的纳秒

例如,如果您的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>
#
#系统日志
#
类型系统日志
5140端口
绑定本地主机
标记系统日志
#
#Tomcat log4j json输出
#
型尾
path/home/foo/logs/catalina-json.out
pos_文件/home/foo/logs/fluentd.pos
标记雄猫
格式json
时间键@时间戳
时间格式“%Y-%m-%dT%H:%m:%S.%L%Z”
然后将它们改成这样,并添加一个记录改革器,该改革器添加一个纳秒字段

#
# 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>
#
#系统日志
#
类型系统日志
5140端口
绑定本地主机
标记cleanup.syslog
#
#Tomcat log4j json输出
#
型尾
path/home/foo/logs/catalina-json.out
pos_文件/home/foo/logs/fluentd.pos
tag.tomcat
格式json
时间键@时间戳
时间格式“%Y-%m-%dT%H:%m:%S.%L%Z”
类型记录改革器
time_nano${t=time.now;((t.to_i*100000000)+t.nsec).to_s}
标记${tag_后缀[1]}

然后将time_nano字段添加到kibana仪表盘,并使用它来排序,而不是@timestamp,一切都会井然有序。

谢谢您的回答。这里有一个流利的维护人员。我会记住这个问题,因为我们会更多地考虑次秒时间戳支持(这是一个已知的问题/设计决策)。感谢大家关注这个问题Kiyoto Tamura。这种解决方法不太理想,因为时间戳是从fluentd vs生成的,而日志文件可能已经具有至少毫秒的精度。最好先将毫秒精度用于时间格式,然后在解析时将fluentd中当前秒的当前纳秒值相加,以保持相同毫秒的顺序。或者,如果解析的日志消息只有1秒的分辨率,比如syslog.Hi@DavidWartell,您认为使用fluent plugin record reformer中的变量${time}更好吗?现在我们可以得到事件的时间,而不是fluentd的时间。@DavidWartell,感谢分享您的解决方案。我也有同样的问题@clarete,我最初只是使用
${time}
,这显然不起作用。我尝试在David Wartell的解决方案中用
${Time}
替换
Time.now
,但这也不起作用。最后几个数字都是零。我认为这是因为
${time}
的存储时间不超过秒。您将其转换为字符串有什么具体原因吗?为什么不直接返回值作为?