A DevOps engineer needs to configure automated real-time alerts whenever a specific error pattern (`[ERROR] Database connection failed`) is written to a custom application log file on a fleet of Compute Engine virtual machines. The solution must adhere to current Google Cloud recommended practices and follow the principle of least privilege. Which set of steps should the engineer execute?
- Install the Google Cloud Ops Agent on the virtual machines, configure a custom log receiver in config.yaml to ingest the log file path, create a counter log-based metric in Cloud Logging for the error pattern, and set up a Cloud Monitoring alerting policy based on that metric.Answer
- BInstall the legacy Stackdriver Logging Agent on the virtual machines, configure an Uptime Check in Cloud Monitoring targeting the local log file directory, and configure an alert policy triggered by disk I/O metrics.
- CInstall the Google Cloud Ops Agent on the virtual machines, assign the primitive Owner role to the Compute Engine default service account, and construct a custom script to poll Cloud Logging via gcloud commands every minute.
- DEnable the Cloud Logging and Cloud Monitoring APIs at the Google Cloud Organization resource level, leave them disabled in the host project, and configure an organization policy to forward log errors to Cloud Monitoring.
Answer
The engineer should install the Google Cloud Ops Agent on the virtual machines, configure a custom log receiver in `config.yaml` for the log file path, create a counter log-based metric in Cloud Logging matching the error string, and set up an alerting policy in Cloud Monitoring based on that metric.
To monitor custom local application logs on Compute Engine VMs, the Google Cloud Ops Agent must be installed and configured with a file receiver in `config.yaml`. To trigger alerts on specific text patterns inside those logs, a counter log-based metric must be created in Cloud Logging to convert matching log entries into time-series metric data. Finally, a Cloud Monitoring alerting policy can be configured on that metric threshold.
Step-by-Step Solution
Key Concept
Log-Based Metrics and Ops Agent Configuration for Compute Engine Observability