An application running in Amazon ECS container tasks writes structured JSON logs to Amazon CloudWatch Logs. A sample log event is:
{
"eventType": "DatabaseError",
"details": {
"duration": 4500,
"status": "failed"
}
}
A developer wants to create a CloudWatch Metric Filter to monitor events where the event type is "DatabaseError" and the nested query duration is greater than milliseconds. The developer initially configures a metric filter with the pattern `[eventType = "DatabaseError", details.duration > 4000]`, but notices that the metric is not being published and no matches are found. Which of the following actions must the developer take to resolve this issue and successfully monitor the database errors? (Select TWO.)
- Update the filter pattern to use curly braces and JSON path notation: `{ .eventType = "DatabaseError" && .details.duration > 4000 }`Cevap
- Specify a metric name, a metric namespace, and a metric value of in the metric filter configuration.Cevap
- CUpdate the filter pattern to use double equals for the string comparison: `{ .eventType == "DatabaseError" && .details.duration > 4000 }`
- DAttach an IAM policy to the ECS Task Role that grants the `cloudwatch:PutMetricData` permission to allow the container to publish the filtered metrics.
- EConfigure a CloudWatch subscription filter to route the logs to an Amazon Kinesis Data Firehose delivery stream, as standard metric filters cannot inspect nested JSON structures.
Cevap
Update the filter pattern to use curly braces and JSON path notation, and specify a metric name, a metric namespace, and a metric value of 1 in the metric filter configuration.
To successfully capture and record metrics from the JSON logs, two actions are required. First, the filter pattern must match the structured JSON schema. This is achieved by enclosing the expression in curly braces and using JSON path notation with a single equals sign for string comparison. Second, the metric filter must be configured with a metric namespace, metric name, and a metric value to indicate how CloudWatch should generate the data point when a log matches the pattern.
Adım Adım Çözüm
Anahtar Kavram
CloudWatch Logs Metric Filter JSON Syntax and Lifecycle
Tahmini Süre:2m 0s