AWS Cloudwatch Json Metric Filter Pattern

ぃ、小莉子 提交于 2020-02-25 05:43:05

问题


Following the Amazon Example for Json Metric Filter,
I tried to copy their example. In the process of creating a metric filter, you can test it with example logs first. So I went for "Custom Log", copy-pasted the example from the link given above:

{
  "eventType": "UpdateTrail",
  "sourceIPAddress": "111.111.111.111",
  "arrayKey": [
        "value",
        "another value"
  ],
  "objectList": [
       {
         "name": "a",
         "id": 1
       },
       {
         "name": "b",
         "id": 2
       }
  ],
  "SomeObject": null,
  "ThisFlag": true
}  

and my pattern is: { $.eventType = "UpdateTrail" } as stated in the example

This is the output of "Test Pattern":

Found 0 matches out of 20 event(s) in the sample log.

How to use them correctly? I seem to not quite grasp the concept.

Update from my side: It seems to have problems with line breaks, for my own purposes I just put my entire custom json into one line which is published by logger.info(json.dumps(my_message)).
I put this "fix" here in case someone stumbles upon the same problem.
I'd still like to hear a general solution!


回答1:


When using the Test Metric Filter feature in the AWS Console, each log event has to be in a separate line. You can still run the same test, but you have to remove all new lines from the sample data.



来源:https://stackoverflow.com/questions/52059922/aws-cloudwatch-json-metric-filter-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!