繁体   English   中英

Fluentbit 解析 json

[英]Fluentbit parse json

我正在使用 fluentbit 来解析日志。 我有下一种格式的日志:

{"key1":"value1","key2":"{\n \"date\": \"2021-07-05 13:58:20.501636\",\n    \"timezone_type\": 3,\n    \"timezone\": \"UTC\"\n}", "key3":"{ \n \"somedata\": \"somevalue\" "}

在 ES 和 Kibana 中,我得到类似的东西:

key1: value1
key2: {
        date: 2021-07-05 13:58:20.501636
        timezone_type: 3
        timezone: UTC
      }
key3: {
        somedata: somevalue
      }

所以,有些字段解析,但我想解析所有字段,比如

key1: value1
key2.date: 2021-07-05 13:58:20.501636
key2.timezone_type: 3
key2.timezone: UTC
key3.somedata: somevalue

使用 fluentbit 配置:

[FILTER]
    Name parser
    Parser api
    Match *
    Reserve_Data On
    Reserve_Key On
    Key_Name log
    Merge_Log  on
    Merge_JSON_Key log
[PARSER]
    Name   api
    Format json
    Time_Key date
    Time_Format %Y-%m-%d %H:%M:%S.%u
    Time_Keep On

我尝试使用Decoders解码字段,例如Decode_Field_As escaped log ,但没有,日志写入格式相同。

您应该使用 Decode_Field_As json 日志代替 Decode_Field_As 转义日志

它将 Json 解码为 kibana 中的不同字段。

谢谢

两个潜在问题:

  1. 问题可能与正在使用的过滤器有关。 而不是Merge_JSON_Key log尝试Merge_Log_Key log_processed 请注意,我们也将值更改为log_processed

     [FILTER] Name parser Parser api Match * Reserve_Data On Reserve_Key On Key_Name log #Not sure if this is necessary?? Merge_Log on Merge_Log_Key log_processed
  2. 如果这不起作用,那么它可能与数据有关。 从外观上看,json 数据作为string对象而不是json发送到日志。

在此处查看我的其他答案,该答案解释了我们如何解决类似问题: How to split log (key) field with fluentbit?

暂无
暂无

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

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