A developer is deploying a Go-based web application to Amazon EC2 instances. The application logs HTTP requests in a custom space-delimited format to /var/log/app/web.log. The fields in each log entry are: IP, client, user, datetime, request_path, response_status, and response_time_ms. The developer wants to use the unified CloudWatch agent to publish these logs to CloudWatch Logs and then create a metric filter to track only requests that returned an HTTP 404 response status. Which two configuration steps must the developer perform to meet these requirements?
- In the CloudWatch agent configuration file, specify the log file path under the logs.logs_collected.files section and define a target log group.Answer
- Create a CloudWatch Logs metric filter on the target log group using the pattern [ip, client, user, datetime, request_path, response_status = 404, response_time_ms].Answer
- CCreate a CloudWatch Logs metric filter on the target log group using the pattern { $.response_status = 404 }.
- DCreate a CloudWatch Logs metric filter on the target log group using the pattern [response_status = 404].
- EIn the CloudWatch agent configuration file, specify the log file path under the metrics.metrics_collected section to enable log streaming.
Answer
To monitor the space-delimited log file, the developer must configure the log file path under the logs.logs_collected.files section of the unified CloudWatch agent configuration file, and create a CloudWatch Logs metric filter with the pattern [ip, client, user, datetime, request_path, response_status = 404, response_time_ms].
To stream local log files to CloudWatch Logs, the unified CloudWatch agent must be configured with the file path in the logs.logs_collected.files section. To create a metric filter for space-delimited logs, the filter pattern must list all fields in order, enclosed in brackets, and use the assignment operator to filter on the specific HTTP status code.
Step-by-Step Solution
Key Concept
Configuring log collection with the unified CloudWatch agent and applying space-delimited metric filter patterns.