Creating an alerting policy
Alerting policies for the burn rate of your error budget are based on thetime-series selectorselect_slo_burn_rate, described inRetrieving SLOdata. There are other time-series selectors, and you can use some ofthem as the basis for alerting policies. For a discussion of SLO-basedalerting policies, seeAlerting on your burn rate.
You create alerting policies by using thealertPolicies.create method. The general use ofthis method is documented inManaging alerting policies.
Alerting policies for SLOs are similar to other metric-threshold alertingpolicies, but they differ in one specific way: thefilterin theMetricThreshold specification of thecondition uses a time-series selector instead of a pair of metric andmonitored-resource types.
Conditions for SLO-based alerting policies
An alerting policy must have at least one condition. For a SLO-basedcondition, use aMetricThreshold-type condition.
A metric-threshold condition can contain two pairs of time-seriesconfigurations:filter andaggregations. Because SLO datais retrieved differently than other time-series data, the only field usedin a condition for an SLO is thefilter field.
A condition for an SLO does set thecomparison,thresholdValue,duration,andtrigger fields.
This example creates a condition that is violated when the burn rateexceeds 2 times the normal rate. The structure looks like this:
"conditions": [ { "displayName":"SLO burn rate alert for ${SLO_ID} exceeds 2", "conditionThreshold": { "filter":DATA_RETRIEVAL_FILTER_FOR_SLO, "comparison":"COMPARISON_GT", "thresholdValue": 2, "duration": { "seconds":"0", }, }, } ],To set thefilter field, you need the resource name of a specific SLO. Thisvalue is of the formprojects/${PROJECT}/services/${SERVICE_ID}/serviceLevelObjectives/${SLO_ID}.For information on finding the SLO ID, seeListing SLOs.
To create an alert on burn rate, use the time-series selectorselect_slo_burn_rate. This selector takes two values, the target SLOand the lookback period. For more information, seeselect_slo_burn_rate.
For example, the following filter gets the burn rate of the target SLO with a1-hour lookback period:
"filter":"select_slo_burn_rate(\"projects/${PROJECT}/services/${SERVICE_ID}/serviceLevelObjectives/${SLO_ID}\", \"60m\")"
The rest of the alerting policy
To complete the alerting policy, specify values for the remaining fields:
displayName: A description of the alerting policy.combiner: Describes the logic for combining conditions. This policyhas only one condition, so eitherANDorORworks.notificationChannels: An array of existing notification channels touse when the alerting policy is triggered. For information on findingand creating notification channels, seeNotification channels.documentation: Information that is sent when the condition is violatedto help recipients diagnose the problem. For details, seeDocumentation.
Creating the alerting policy
The following example uses the API to create a burn-rate alerting policy.For information about listing, modifying, and deleting alerting policies,seeManaging alerting policies by API.
Protocol
To create the alerting policy by usingcurl, send aPOST messageto thehttps://monitoring.googleapis.com/v3/projects/${PROJECT_ID}/alertPolicies endpoint, and provide thealerting policy in the request body. The JSON in the request body describesan alerting policy that uses a threshold condition based on theselect_slo_burn_rate time-series selector with a one-hour lookback period.Create a variable to hold the request body:
CREATE_ALERT_POST_BODY=$(cat<<EOF{"displayName":"SLOburn-ratealertfor${SLO_ID}withathresholdof2","combiner":"AND", "conditions":[{ "displayName":"SLOburnratealertfor${SLO_ID}exceeds2", "conditionThreshold":{"filter":"select_slo_burn_rate(\"projects/${PROJECT}/services/${SERVICE_ID}/serviceLevelObjectives/${SLO_ID}\",\"60m\")", "comparison":"COMPARISON_GT", "thresholdValue":2, "duration":{ "seconds":"0", },}, }],"notificationChannels":["${NOTIFICATION_CHANNEL}",],"documentation":{"content":"SLOburnforthepast60mexceededtwicetheacceptablebudgetburnrate.","mime_type":"text/markdown",},}EOF)Post the request to the endpoint:
curl--http1.1--header"Authorization:Bearer${ACCESS_TOKEN}"--header"Content-Type:application/json"-XPOST-d"${CREATE_ALERT_POST_BODY}"https://monitoring.googleapis.com/v3/projects/${PROJECT_ID}/alertPolicies
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-11-05 UTC.