Alert on log-based metrics

This document explains how to configure notifications when a log-based metric matches criteria that you specify. These instructions, which guide you through creating an alerting policy and configuring notification channels, are for the Google Cloud console. You can also create alerting policies by using the Cloud Monitoring API and by using the Google Cloud CLI command gcloud alpha monitoring policies.

Before you begin

  1. Ensure that your Identity and Access Management role includes the permissions required to create and view log-based metrics, and to create alerting policies. For details, see Log-based metric permissions.

  2. Ensure that you are familiar with log-based metrics. For more information, see Overview of log-based metrics.

  3. Configure the notification channels that you want to use to receive any alerts. For information about these steps, see Manage notification channels.

Create an alerting policy on a counter metric

An alerting policy describes a set of conditions that you want to monitor. When you create an alerting policy, you must also specify its conditions: what is monitored and when to trigger an alert. When an alert triggers, notifications are sent to the notification channels included in the policy. The notification includes information about the alert, and it includes buttons that let you view relevant logs and incident details:

Display of the view logs button on an alert notification.

To create an alerting policy on a log-based counter metric, do the following:

  1. In the Google Cloud console, select Logging, and then select Log-based metrics, or click the following button:

    Go to Log-based metrics

  2. To find the metric you want to alert on, click More, and then select Create alert from metric.

  3. Ensure that the Enter a Monitoring filter field lists a metric.type and a resource.type. If necessary, add a resource.type clause.

    For example, the following filter specifics a metric and a resource:

    AND resource.type="gce_instance"
  4. Click Next, enter a value in the Threshold value field.

  5. Click Next, click Notification channels, and then select the notification channels that you want to use for the alert.

  6. Optional: In the Documentation section, enter any information that you want included in notifications. Typically, the information includes information about how to respond to the alert notification.

  7. In the Name the alert policy field, enter a name for the alerting policy.

  8. Click Create policy.


If you encounter issues, see Troubleshoot log-based metrics.

What's next