我正在尝试使用FluentD收集日志,但我得到了以下错误;
2021-08-31 05:37:03 +0000 [warn]: #0 [tail_container_logs] pattern not match: "2021-08-31T05:37:03.133785104Z stderr F I0831 05:37:03.130864 1 main.go:227] handling current node"
2021-08-31 05:37:06 +0000 [warn]: #0 [tail_container_logs] pattern not match: "2021-08-31T05:37:05.474234466Z stdout F Hello world"
2021-08-31 05:37:08 +0000 [warn]: #0 [tail_container_logs] pattern not match: "2021-08-31T05:37:07.195447969Z stderr F 2021-08-31 05:37:07.195301 I | etcdserver/api/etcdhttp: /health OK (status code 200)"我的fluent.conf文件如下;
<source>
@type tail
@id tail_container_logs
path /var/log/containers/*.log
pos_file /var/fluent/log/containers.log.pos
time_format %Y-%m-%dT%H:%M:%S.%NZ
tag kubernetes.*
exclude_path "/var/log/containers/my-fluent*.log"
read_from_head true
<parse>
@type json
time_format %Y-%m-%dT%H:%M:%S.%NZ
</parse>
</source>
<filter kubernetes.**>
@type kubernetes_metadata
</filter>
<match kubernetes.**>
@type file
@id output1
path /var/fluent/log/log/data.*.log
append true
</match>当我检查运行kind kubernetes集群的主机(而不是kubernetes节点)上的Docker日志记录驱动程序配置时,它显示json-file为日志记录驱动程序。
但是,我无法在CRI的节点中找到日志记录驱动程序配置。当我连接到节点并运行crictl info时,它显示了配置,但没有日志记录驱动程序。经过进一步的研究,我发现cri-o日志记录没有json支持。我怀疑唯一可用的选项是在FluentD配置中使用@type正则表达式。
关于如何在fluentD中解析cri-o日志,有什么建议吗?
提前感谢!
发布于 2021-08-31 10:05:22
我能够使用在fluent-bit主题中找到的正则表达式来解析cri-o日志。以下是部件的fluentD配置。
<source>
@type tail
@id tail_container_logs
path /var/log/containers/*.log
pos_file /var/fluent/log/containers.log.pos
time_format %Y-%m-%dT%H:%M:%S.%NZ
tag kubernetes.*
exclude_path "/var/log/containers/my-fluent*.log"
#format json_in_json
read_from_head true
<parse>
@type regexp
expression /^(?<time>.+)\b(?<stream>stdout|stderr)\b(?<log>.*)$/
time_key time
time_format %Y-%m-%dT%H:%M:%S.%NZ
</parse>
</source>目前还没有用于FluentD的cri-o解析器。
https://stackoverflow.com/questions/68993514
复制相似问题