【问题标题】:Fluentbit - parsing log with multiple format (log+json)Fluentbit - 解析多种格式的日志(log+json)
【发布时间】:2020-12-29 10:02:48
【问题描述】:

我正在尝试通过fluentbit将以下日志行发送到elasticsearch,但在[MLP]部分之后我没有找到正确的解决方案来提取时间和json结构:

2020-12-29 08:00:03,230 INFO [http-nio-3410-exec-7] c.e.m.p.PushManager$ImportResponseImpl - [MLP] {"component":{"name":"importserv","version":"5.4.2"},"details":{"feed":"SomeFEED"},"elapsedMs":354,"event":"import","id":"1.0.58855123705431","name":"image1.png","objType":"Image","outcome":"OK","uuid":"1234566573234242342-123434234-12342"}

有人尝试过实现这样的目标吗?欢迎提出意见和建议。

谢谢!

【问题讨论】:

    标签: mlp fluent-bit


    【解决方案1】:

    您可以为此使用regex parser

    [PARSER]
        Format regex
        Name logging-parser
        Regex ^(?<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}) (?<level>\S+) .* (?<capturedJson>{.*})$
        Decode_Field json capturedJson
        Time_Format %FT%H:%M:%S,%L
        Time_Key time
    

    首先,编写一个正则表达式,将您的 json 捕获到一个单独的组中。您可以使用 Rubular 来测试表达式。这是一个解析你的输入的例子,json被捕获为capturedJsonhttps://rubular.com/r/NAby4NlVomkdWy

    接下来,添加Decode_Field json capturedJson - 这将解析组中捕获的 json 并提取其字段,因此它们是可搜索的。

    上面的代码未针对您的场景进行测试,但我们使用类似的代码来解析也包含 json 的 envoy 日志。

    【讨论】:

      猜你喜欢
      • 2021-09-16
      • 2013-01-09
      • 2020-09-14
      • 2020-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多