Soru

Zorluk: KolayMonitoring and Analyzing Logs with Amazon CloudWatch

A developer is configuring a CloudWatch Metric Filter to count the occurrences of HTTP 5xx errors from a web application's JSON-formatted log group. The JSON log events have the structure: `{"statusCode": 500, "message": "Internal Server Error"}`. The metric filter must count all events where `statusCode` is greater than or equal to 500. Which of the following configurations are required to correctly achieve this? (Select TWO.)

  1. Define the metric filter pattern as `{ $.statusCode >= 500 }` to match the JSON key-value pair.Cevap
  2. Set the metric value in the filter configuration to 1 to increment the metric count by 1 for each matching log event.Cevap
  3. C
    Define the metric filter pattern as `[statusCode >= 500]` using space-delimited syntax.
  4. D
    Increase the execution timeout of the application's AWS Lambda function to allow CloudWatch Logs more time to process the metric filter.
  5. E
    Configure an IAM Trust Policy on the log group to allow it to assume the role required to run the metric filter.

Cevap

Define the metric filter pattern as `{ $.statusCode >= 500 }` and set the metric value in the filter configuration to 1.
The correct options are the ones stating to define the metric filter pattern as `{ .statusCode >= 500 }` and to set the metric value in the filter configuration to 1. CloudWatch Logs supports filtering JSON log messages using curly braces `{}` and the `.property` notation to inspect properties of the JSON object. Specifying a metric value of 1 instructs CloudWatch to increment the metric by 1 for each matching log event.

Adım Adım Çözüm

1
Select the correct pattern syntax for JSON logs.
The JSON pattern syntax requires curly braces `{}` and the JSON path operator `.` to target the `statusCode` field (e.g., `{ .statusCode >= 500 }`).
CloudWatch Logs parses JSON events dynamically, but requires the correct query structure to extract fields.
2
Configure the metric increment value.
A metric value of 1 is specified to increment the custom metric count per occurrence.
This registers each matched error event as a single count for monitoring purposes.

Anahtar Kavram

CloudWatch Logs Metric Filters syntax and configuration for JSON-formatted log events.
Tahmini Süre:1m 0s
Bu soruyu puanla