A developer is configuring an Amazon CloudWatch Logs metric filter to monitor HTTP 500 status codes for a legacy web application. The application logs events to a CloudWatch log group in space-delimited Common Log Format (CLF). The developer observes the following sample log event:
`192.0.2.10 - - [14/Jul/2026:12:00:00 +0000] "POST /submit HTTP/1.1" 500 324`
The developer sets up the metric filter with the following pattern:
`[ip, client, user, timestamp, request, status_code = 500, size]`
However, the metric does not record any data points even when the log group receives events containing HTTP 500 errors. What is the reason for this behavior?
- The metric filter parser splits the log line strictly by spaces, ignoring brackets and quotes. This causes the timestamp and HTTP request to be parsed into multiple fields, shifting the status code to the ninth position.Cevap
- BThe metric filter pattern syntax requires double equal signs for comparison operators in space-delimited logs, meaning the pattern should be updated to status_code == 500.
- CThe metric filter must use JSON syntax to query the log event properties because the web server logs are structured, which requires changing the pattern to a JSON path query.
- DThe timestamp and request fields in the pattern must be enclosed in single quotes to instruct the parser to treat them as single entities, rather than splitting them on spaces.
Cevap
The metric filter parser splits the log line strictly by spaces, ignoring brackets and quotes. This causes the timestamp and HTTP request to be parsed into multiple fields, shifting the status code to the ninth position.
The correct answer explains that CloudWatch Logs parses space-delimited log events strictly by spaces, ignoring enclosing brackets (like those on timestamps) or quotes (like those around requests). Consequently, the log line is split into ten fields instead of seven, shifting the status code to the ninth position. To fix the issue, the metric filter pattern must declare fields up to the ninth position, such as: `[ip, client, user, timestamp_date, timestamp_zone, method, path, protocol, status_code = 500, size]`.
Adım Adım Çözüm
Anahtar Kavram
CloudWatch Logs space-delimited metric filters parse raw log entries strictly by space boundaries without respecting quotes or brackets for grouping.
Tahmini Süre:1m 30s