A SysOps Administrator is setting up monitoring for a microservice that writes JSON-formatted application logs to an Amazon CloudWatch Logs log group. The logs contain a field named `status` indicating the outcome of each transaction. The administrator needs to create a metric filter to count how many times a transaction ends with a status of `FAILED`.
How should the administrator configure this metric filter?
- AConfigure the log group retention setting to only retain logs matching `{ $.status = "FAILED" }`, which automatically populates a custom metric.
- BEnable detailed monitoring on the EC2 instance hosting the microservice, which automatically enables JSON log parsing and creates a default CloudWatch metric named `status`.
- Create a metric filter with the pattern `{ $.status = "FAILED" }` to match the JSON log structure and increment a custom metric.Cevap
- DCreate an Amazon EventBridge rule that triggers on any write to the log group, and configure a Systems Manager Automation document to parse the JSON logs and increment the metric.
Cevap
Create a metric filter with the pattern `{ $.status = "FAILED" }` to match the JSON log structure and increment a custom metric.
The correct action is to create a metric filter with the pattern `{ $.status = "FAILED" }`. CloudWatch Logs supports filtering JSON log events by specifying the property path prefixed by a dollar sign and dot inside curly braces. This allows CloudWatch to match events where the status field is FAILED and increment a custom metric accordingly.
Adım Adım Çözüm
Anahtar Kavram
CloudWatch Logs Metric Filters for JSON logs