Amazon Cloudwatch Logs Insights with JSON fields

后端 未结 5 764
执笔经年
执笔经年 2020-12-28 13:18

I am trying to use Logs Insights with data containing JSON in one of the fields, and to parse the JSON fields

My data looks like the following when I put it in insig

5条回答
  •  忘掉有多难
    2020-12-28 14:23

    You can use the parse command to extract fields.

    If @message is

    I, [2018-12-11T13:20:27] INFO -- : {"method":"GET"}
    

    Then you extract the fields like so:

    fields @timestamp, @message
    | parse "I, [*T*] INFO -- : {"method":"*"}" as @date, @time, @method
    | filter method=GET
    | sort @timestamp desc
    | limit 20
    

    The documentation is rather light for now. I am able to get results by replacing the wildcard * with a regular expression, but then the parsing fails.

提交回复
热议问题