
StackDriver自定义内涵多行记录,时间格式-英雄云拓展知识分享
我一直在尝试设置一个自定义内涵的多行日志解析器,以将日志带入使用一些可读字段的堆叠式驱动器。至今为止看起来像这样:
<source>type tail
read_from_head true
path /root/ansible.log
pos_file /var/lib/google-fluentd/pos/ansible.pos
time_format "%a %b %e %T %Z %Y"

format multiline
format_firstline /Started ansible run at/
format1 /Started ansible run at (?<timestart>[^\n]+)\n(?<body>.*)/
format2 /PLAY RECAP.*/
format3 /ok=(?<ok>\d+)\s+changed=(?<changed>\d+)\s+unreachable=(?<unreachable>\d+)\s+failed=(?<failed>\d+).*/
format4 /Finished ansible run at (?<timeend>[^\n]+)/
tag ansible
</source>
它已完成了规格 http://docs.fluentd.org/v0.12/articles/parser_multiline,它起作用。但是它没有适当的时间戳记 - timestart
和 timeend
只是JSON中的简单字段。因此,这种情况下,在当前状态下 time_format
设置没有用,由于我没有 time
言论之间的变量。这确切汇总了我需要的所有变量,当我运行Fluend Service时,在StackDriver中显示了日志,几近所有人都很高兴。
但是,当我将这些时间变量的名称之一更改成 time
,试图将堆叠式驱动器时间戳分配给条目,它不起作用。机器上的流利登录说,工人开始并解析了所有内容,但日志根本不会显示在StackDriver控制台中。
timestart
和 timeend
看起来像 Fri Jun 2 20:39:58 UTC 2017
或类似的规定。时间格式规范在 http://ruby-doc.org/stdlib⑵.4.1/libdoc/time/rdoc/time.html#method-c-strptime 而且我已检查并仔细检查了很屡次,我没法弄清楚我做错了甚么。
编辑:另外一个细节:当我尝试解析 time
变量,虽然日志未显示在堆栈驱动器控制台中,但适当的标签(在这类情况下 ansible
)显示在标签列表中。只是结果是空的。
正确的是,StackDriver Logging Agent在此处寻觅时间戳 'time'
字段,但它使用了Ruby的 time.iso8601 解析该价值(倒退 时间 毛病)。您援用的字符串(Fri Jun 2 20:39:58 UTC 2017
)不采取任何一种格式,因此它没法解析(您可能会在 /var/log/google-fluentd/google-fluentd.log
)。你可以添加一个 record_transformer 插件到您的配置,将分析日期更改成正确的格式(提示: enable_ruby
是你的朋友)。就像是:
<filter foo.bar>@type record_transformer
enable_ruby
<record>
time ${Time.strptime(record['time'], '%a %b %d %T %Z %Y').iso8601}
</record>
</filter>
应当管用...
暂时没有评论,来抢沙发吧~