Soru

Zorluk: KolayCloudWatch Logs and Metric Filters

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?

  1. A
    Configure the log group retention setting to only retain logs matching `{ $.status = "FAILED" }`, which automatically populates a custom metric.
  2. B
    Enable detailed monitoring on the EC2 instance hosting the microservice, which automatically enables JSON log parsing and creates a default CloudWatch metric named `status`.
  3. Create a metric filter with the pattern `{ $.status = "FAILED" }` to match the JSON log structure and increment a custom metric.Cevap
  4. D
    Create 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

1
Define the target filter pattern for JSON logs.
The pattern `{ $.status = "FAILED" }` is selected to target the status key in the log event JSON object.
CloudWatch Logs uses curly braces and the `$.<property>` syntax to parse and evaluate JSON formatted logs.
2
Associate the filter pattern with a new metric in the CloudWatch Logs console or CLI.
A custom metric namespace and metric name are defined, along with a metric value (typically 1) to increment on each match.
This establishes the relationship between the parsed log event and the CloudWatch metric system.

Anahtar Kavram

CloudWatch Logs Metric Filters for JSON logs
Bu soruyu puanla