A platform engineering team operates a legacy web application on a fleet of Compute Engine instances. The application writes structured JSON operational logs to a local file at `/var/log/app/service.log`. The team needs to configure automated real-time operational alerts in Cloud Monitoring whenever the frequency of HTTP 5xx server errors parsed from this log file exceeds 50 occurrences within a 1-minute rolling window across the fleet. The solution must follow Google Cloud best practices for observability and operational alerting. Which approach should the team implement?
- Install and configure the Google Cloud Ops Agent on the Compute Engine instances to collect and parse the custom log file. Create a Cloud Logging log-based counter metric with a filter matching HTTP 5xx response codes, and configure a Cloud Monitoring alert policy based on the log-based metric threshold exceeding 50 per minute.Answer
- BGrant the primitive Owner role (`roles/owner`) to the default Compute Engine service account on the project, configure Cloud Audit Logs to track instance file updates, and create a Cloud Monitoring metric threshold alert directly monitoring instance disk write operations.
- CGrant the Service Account Admin role (`roles/iam.serviceAccountAdmin`) to the application service account, create a Cloud Logging sink that exports all logs to a BigQuery dataset, and schedule a BigQuery SQL query to execute every minute to send email notifications.
- DSubmit a regional quota increase request for Cloud Logging ingestion API quota prior to deployment, configure the instances to stream unparsed raw logs directly to Cloud Storage, and set up a Cloud Monitoring alert policy on the default VM CPU utilization metric.
Answer
Install and configure the Google Cloud Ops Agent on the Compute Engine instances to collect and parse the custom log file, create a Cloud Logging log-based counter metric with a filter matching HTTP 5xx response codes, and configure a Cloud Monitoring alert policy based on the log-based metric threshold exceeding 50 per minute.
The correct approach uses the Ops Agent to collect and parse custom application logs from Compute Engine instances. Creating a Cloud Logging log-based metric extracts a count of HTTP 5xx errors into Cloud Monitoring, where an alert policy can monitor the metric threshold (50 errors per minute) and trigger notifications appropriately.
Step-by-Step Solution
Key Concept
Configuring Cloud Logging log-based metrics and Cloud Monitoring alert policies for custom application logs