【问题标题】:How to expand JSON in Fluentd?如何在 Fluentd 中扩展 JSON?
【发布时间】:2020-09-28 15:32:58
【问题描述】:

有没有办法将嵌套的 JSON 字符串过滤到 fluentd 中的单独字段中?

当前 JSON:

 { 
   Value1: "something",
   Value2: "something",
   Message:{
             Value3: "Something",
             Value3: "Something"
          }
 }

我想要什么(或类似的东西):

 { 
   Value1: "something",
   Value2: "something",
   Message.Value3: "Something",
   Message.Value3: "Something"
          
 }

JSON 不必像上面的示例那样被展平,但我确实希望这些值在到达 elasticsearch 时位于它们自己的单独字段(列)中。在其他方面,我想将单个长消息字符串拆分为包含在其中的多个字段。

【问题讨论】:

    标签: fluentd


    【解决方案1】:

    试试这个:

    <source>
    ...
    </source>
    
    <filter myapp**>
      @type parser
      key_name Message
    
      format multi_format
      <pattern>
        format json # try parsing json in the first place
      </pattern>
      <pattern>
        format none # leave as is if this is not json (plaintext)
      </pattern>
    
      reserve_data true # keep the original Message field in case anything go wrong
    </filter>
    
    <match myapp**>
    ...
    </match>
    

    多格式解析器:https://github.com/repeatedly/fluent-plugin-multi-format-parser

    【讨论】:

    • 哇。就这么容易?我的英雄。确认工作:)
    猜你喜欢
    • 1970-01-01
    • 2019-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多