Soru

Zorluk: OrtaMonitoring and Analyzing Logs with Amazon CloudWatch

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 40004000 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.)

  1. Update the filter pattern to use curly braces and JSON path notation: `{ .eventType = "DatabaseError" && .details.duration > 4000 }`Cevap
  2. Specify a metric name, a metric namespace, and a metric value of 11 in the metric filter configuration.Cevap
  3. C
    Update the filter pattern to use double equals for the string comparison: `{ .eventType == "DatabaseError" && .details.duration > 4000 }`
  4. D
    Attach an IAM policy to the ECS Task Role that grants the `cloudwatch:PutMetricData` permission to allow the container to publish the filtered metrics.
  5. E
    Configure 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

1
Correct the log format interpretation in the filter pattern.
Change the pattern from space-delimited text syntax `[eventType = "DatabaseError", details.duration > 4000]` to JSON syntax `{ .eventType = "DatabaseError" && .details.duration > 4000 }`.
CloudWatch Logs requires curly braces `{}` and the `$.` prefix to query nested properties in JSON log events.
2
Map the filter matches to a target metric.
Define the target metric's namespace, name, and increment value (11).
A metric filter must specify how matching log events translate into custom metric data points in Amazon CloudWatch.

Anahtar Kavram

CloudWatch Logs Metric Filter JSON Syntax and Lifecycle
Tahmini Süre:2m 0s
Bu soruyu puanla