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 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:
To create an alerting policy that compares the value of a log-based counter metric to a threshold, do the following:
-
In the Google Cloud console, go to the Log-based Metrics page:
If you use the search bar to find this page, then select the result whose subheading is Logging.
Find the metric that you want to monitor, click more_vert More, and then select Create alert from metric.
Ensure that the Enter a Monitoring filter field lists a
metric.type
and aresource.type
. If necessary, add aresource.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"
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 to2N
minutes or 10 minutes, whichever is larger.Click Next, select Threshold.
Enter a Threshold value, and optionally, configure the Alert trigger and Threshold position fields.
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.
Click Next, click Notification channels, and then select the notification channels that you want to use for the alerting policy.
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.
In the Name the alert policy field, enter a name for the alerting policy.
Click Create policy.
Troubleshooting
If you encounter issues, then see Troubleshoot log-based metrics.
What's next
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 receive notifications you when you approach the threshold for billing, see Alerting on usage.