Question

Difficulty: EasyMonitoring and Logging

An application developer needs to receive an automated email notification whenever a specific error code string appears in the log stream of a Google Cloud application. What is the Google-recommended method to accomplish this requirement?

  1. Create a log-based counter metric matching the error string filter, and create a Cloud Monitoring alerting policy based on that metric with an email notification channel.Answer
  2. B
    Install the legacy Stackdriver Logging Agent on the instance host and configure a custom script to forward log files directly to a Pub/Sub topic for email delivery.
  3. C
    Assign the Primitive Owner role to the developer account so Cloud Logging automatically triggers email alerts for all application logs containing errors.
  4. D
    Enable the Cloud Monitoring API at the organization node level and enforce an Organization Policy constraint that forwards matching logs to email.

Answer

Create a log-based counter metric matching the error string filter, and create a Cloud Monitoring alerting policy based on that metric with an email notification channel.
The standard solution in Google Cloud Observability for alerting on specific log contents is to define a log-based counter metric based on a Cloud Logging filter query, then attach a Cloud Monitoring alerting policy with an email notification channel to that metric.

Step-by-Step Solution

1
Filter log entries in Cloud Logging
Identify the precise log entries containing the required error code string using a log filter query.
Log-based metrics extract structured data or count events from matching log entries.
2
Create a log-based metric
A counter metric is generated that increments whenever a matching log entry arrives.
Cloud Monitoring requires a metric stream to define threshold condition alerts.
3
Configure an alerting policy and notification channel
Set a metric threshold condition (> 0) and attach an email notification channel.
When the metric triggers upon detecting the error log pattern, Cloud Monitoring automatically dispatches an email notification.

Key Concept

Log-based Metrics and Alerting Policies
Estimated Time:50s
Rate this question