问题
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