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
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.
Ensure that you are familiar with log-based metrics. For more information, see Overview of log-based metrics.
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:
To create an alerting policy on a log-based counter metric, do the following:
In the navigation panel of the Google Cloud console, select Logging, and then select Log-based Metrics:
To find the metric you want to alert on, click more_vert More, and then select Create alert from metric.
Ensure that the Enter a Monitoring filter field lists a
resource.type. If necessary, add a
For example, the following filter specifics a metric and a resource:
metric.type="logging.googleapis.com/byte_count" AND resource.type="gce_instance"
Click Next, enter a value in the Threshold value field.
Click Next, click Notification channels, and then select the notification channels that you want to use for the alert.
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.
In the Name the alert policy field, enter a name for the alerting policy.
Click Create policy.
If you encounter issues, see Troubleshoot log-based metrics.
For more information about alerting policies, see the following documents:
To chart your log-based metric, see View your log-based metrics.
For information about how to monitor Cloud Logging and Cloud Monitoring usage and alerts you when you approach the threshold for billing, see Alerting on usage.