Fluentd 正则表达式匹配错误
Fluentd Regular Expression Matching Error
我正在尝试像这样解析来自 kubernetes 的日志
2018-08-14 13:21:20.013 [INFO][67] health.go 150: Overall health summary=&health.HealthReport{Live:true, Ready:true}
这是配置
<source>
@id calico-node.log
@type tail
format /^(?<time>[^ ]* [^ ,]*)[^\[]*\[[^\]]*\]\[(?<severity>[^ \]]*) *\] (?<message>.*)$/
time_format %Y-%m-%d %H:%M:%S
path /var/log/containers/calico-node**.log
pos_file /var/log/es-calico.pos
tag calico-node
</source>
根据 regex101.com,此模式应匹配此字符串。但是,我在尝试解析此
时从 fluentd 收到错误消息
2018-08-14 13:21:20 +0000 [warn]: [calico-node.log] "{\"log\":\"2018-08-14 13:21:20.013 [INFO][67] health.go 150: Overall health summary=\u0026health.HealthReport{Live:true, Ready:true}\n\",\"stream\":\"stdout\",\"time\":\"2018-08-14T13:21:20.013908223Z\"}" error="invalid time format: value = {\"log\":\"2018-08-14 13:21:20.013, error_class = ArgumentError, error = string doesn't match"```
有什么问题吗?我对 Apache 日志的内置解析器也有类似的错误?
据我所知,您在 fluentd config
中遗漏了一些内容。
您的 time_format %Y-%m-%d %H:%M:%S
将无法使用时间戳 2018-08-14 13:21:20.013
,因为它丢失了 .%3N
。
应该是这样的:
time_format %Y-%m-%d %H:%M:%S.%3N
或 time_format %Y-%m-%d %H:%M:%S.%L
刚遇到类似的问题。
我认为@Crou 的回答是正确的,但也许可以尝试 %N
。
根据文档,fluentd 解析器不支持 %3N
、%6N
、%9N
和 %L
我正在尝试像这样解析来自 kubernetes 的日志
2018-08-14 13:21:20.013 [INFO][67] health.go 150: Overall health summary=&health.HealthReport{Live:true, Ready:true}
这是配置
<source>
@id calico-node.log
@type tail
format /^(?<time>[^ ]* [^ ,]*)[^\[]*\[[^\]]*\]\[(?<severity>[^ \]]*) *\] (?<message>.*)$/
time_format %Y-%m-%d %H:%M:%S
path /var/log/containers/calico-node**.log
pos_file /var/log/es-calico.pos
tag calico-node
</source>
根据 regex101.com,此模式应匹配此字符串。但是,我在尝试解析此
时从 fluentd 收到错误消息2018-08-14 13:21:20 +0000 [warn]: [calico-node.log] "{\"log\":\"2018-08-14 13:21:20.013 [INFO][67] health.go 150: Overall health summary=\u0026health.HealthReport{Live:true, Ready:true}\n\",\"stream\":\"stdout\",\"time\":\"2018-08-14T13:21:20.013908223Z\"}" error="invalid time format: value = {\"log\":\"2018-08-14 13:21:20.013, error_class = ArgumentError, error = string doesn't match"```
有什么问题吗?我对 Apache 日志的内置解析器也有类似的错误?
据我所知,您在 fluentd config
中遗漏了一些内容。
您的 time_format %Y-%m-%d %H:%M:%S
将无法使用时间戳 2018-08-14 13:21:20.013
,因为它丢失了 .%3N
。
应该是这样的:
time_format %Y-%m-%d %H:%M:%S.%3N
或 time_format %Y-%m-%d %H:%M:%S.%L
刚遇到类似的问题。
我认为@Crou 的回答是正确的,但也许可以尝试 %N
。
根据文档,fluentd 解析器不支持 %3N
、%6N
、%9N
和 %L