簡體   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