繁体   English   中英

解析器部分的 Fluentd 时间格式不起作用

[英]Fluentd time format in parser section doesn't work

嗨,Fluentd 专家和用户!

我发现 Fluentd 解析器无法解析我的 json 格式的时间字段。

坦率地说,我不知道通过解析器后时间应该是什么样子,因为我从来没有成功过。 我参考的配置是这个链接: https://docs.fluentd.org/configuration/parse-section#time-parameters

我的测试用例很简单,输入是一个带有时间字段{"hello":"world", "time":"1991-02-19 00:00:00"}的虚拟 Json。

但是不管我怎么修改时间格式,或者故意把输入时间的格式写错,都不会影响到最后的output,而且最后的output好像只是把时间字段打印成字符串。

这是我的流利配置:

<source>
  @type dummy
  dummy {"hello":"world", "time":"1991-02-19 00:00:00"}
  tag sample
  <parse>
    @type json
    time_type string
    time_format "%Y-%m-%dT%H:%M:%S"
    time_key "time"
    keep_time_key true
  </parse>
</source>

<match sample>
  @type stdout
  @id out_stdout
</match>

output 是:

2022-04-12 01:44:01.034400852 +0000 sample: {"hello":"world","time":"1991-02-19 00:00:00"}
2022-04-12 01:44:02.035744518 +0000 sample: {"hello":"world","time":"1991-02-19 00:00:00"}
2022-04-12 01:44:03.037178309 +0000 sample: {"hello":"world","time":"1991-02-19 00:00:00"}
2022-04-12 01:44:04.038867836 +0000 sample: {"hello":"world","time":"1991-02-19 00:00:00"}
....

可以看到,虽然输入的时间字段中少了一个'T',但是并没有报错和警告,output 只是将原始字符串发送了出去。

如果我将“T”放回输入,output 也会将“T”取回。 配置和 output 是:

<source>
  @type dummy
  dummy {"hello":"world", "time":"1991-02-19T00:00:00"}
  tag sample
  <parse>
    @type json
    time_type string
    time_format "%Y-%m-%dT%H:%M:%S"
    time_key "time"
    keep_time_key true
  </parse>
</source>

<match sample>
  @type stdout
  @id out_stdout
</match>
2022-04-12 01:59:56.026574094 +0000 sample: {"hello":"world","time":"1991-02-19T00:00:00"}
2022-04-12 01:59:57.028190722 +0000 sample: {"hello":"world","time":"1991-02-19T00:00:00"}
2022-04-12 01:59:58.029744904 +0000 sample: {"hello":"world","time":"1991-02-19T00:00:00"}
2022-04-12 01:59:59.031296625 +0000 sample: {"hello":"world","time":"1991-02-19T00:00:00"}
...

所以我很疑惑,fluentd的解析器中的时间格式真的有用吗? 而且我不确定这是 Fluentd 问题还是插件问题,还是我的配置有误。

非常感谢!

dummy / sample输入插件不支持<parse>部分。

只需使用您的配置运行fluentd并在日志中观察到这些警告:

2022-04-12 19:44:56 +0500 [warn]: section <parse> is not used in <source> of sample plugin
2022-04-12 19:44:56 +0500 [warn]: section <parse> is not used in <source> of sample plugin
2022-04-12 19:44:56 +0500 [warn]: section <parse> is not used in <source> of sample plugin
2022-04-12 19:44:56 +0500 [warn]: section <parse> is not used in <source> of sample plugin
2022-04-12 19:44:56 +0500 [warn]: section <parse> is not used in <source> of sample plugin

相反,您可能想要添加<filter>部分,其中类型解析器配置为json格式。

您应该始终检查日志是否有任何问题。 此外,您可以使用-v标志打开调试日志或使用-vv标志打开跟踪日志。

--dry-run标志非常方便地验证配置文件,例如:

fluentd -c fluent.conf --dry-run

fluentd --help将为您提供可用标志的完整列表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM