Configure notifications for 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 notifications. For information about these steps, see Create and 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 send notifications. Notifications include information about the incident, and they include buttons that let you view relevant logs and incident details:

Display of the view logs button on an notification.

To create an alerting policy that compares the value of a log-based counter metric to a threshold, do the following:

  1. In the Google Cloud console, go to the Log-based Metrics page:

    Go to Log-based Metrics

    If you use the search bar to find this page, then select the result whose subheading is Logging.

  2. Find the metric that you want to monitor, 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:

    metric.type="logging.googleapis.com/byte_count"
    AND resource.type="gce_instance"
    
  4. In the Rolling window menu, we recommend that you select a value that is at least 10 minutes. In particular, this value should be large enough to ensure that multiple log entries that match your filter are counted.

    For example, if a log-based metric counts "heartbeat" log entries, which are expected every N minutes, then set the value of the Rolling window menu to 2N minutes or 10 minutes, whichever is larger.

  5. Click Next, select Threshold.

  6. Enter a Threshold value, and optionally, configure the Alert trigger and Threshold position fields.

  7. Optional: Update the Retest window and use the Advanced Options fields to configure how the alerting policy handles missing data. Typically, the default setting is appropriate.

  8. Click Next, click Notification channels, and then select the notification channels that you want to use for the alerting policy.

  9. 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 notification.

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

  11. Click Create policy.

Troubleshooting

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

What's next