[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-12。"],[],[],null,["# Creating an alerting policy\n\nAlerting policies for the burn rate of your error budget are based on the\ntime-series selector `select_slo_burn_rate`, described in [Retrieving SLO\ndata](/stackdriver/docs/solutions/slo-monitoring/api/timeseries-selectors). There are other time-series selectors, and you can use some of\nthem as the basis for alerting policies. For a discussion of SLO-based\nalerting policies, see [Alerting on your burn rate](/stackdriver/docs/solutions/slo-monitoring/alerting-on-budget-burn-rate).\n\nYou create alerting policies by using the\n[`alertPolicies.create`](/monitoring/api/ref_v3/rest/v3/projects.alertPolicies/create) method. The general use of\nthis method is documented in [Managing alerting policies](/monitoring/alerts/using-alerting-api).\n\nAlerting policies for SLOs are similar to other metric-threshold alerting\npolicies, but they differ in one specific way: the `filter`\nin the [`MetricThreshold`](/monitoring/api/ref_v3/rest/v3/projects.alertPolicies#MetricThreshold) specification of the\ncondition uses a time-series selector instead of a pair of metric and\nmonitored-resource types.\n\nConditions for SLO-based alerting policies\n------------------------------------------\n\nAn alerting policy must have at least one condition. For a SLO-based\ncondition, use a [`MetricThreshold`](/monitoring/api/ref_v3/rest/v3/projects.alertPolicies#MetricThreshold)-type condition.\n\nA metric-threshold condition can contain two pairs of time-series\nconfigurations: `filter` and `aggregations`. Because SLO data\nis retrieved differently than other time-series data, the only field used\nin a condition for an SLO is the `filter` field.\n\nA condition for an SLO does set the `comparison`, `thresholdValue`, `duration`,\nand `trigger` fields.\n\nThis example creates a condition that is violated when the burn rate\nexceeds 2 times the normal rate. The structure looks like this: \n\n```\n \"conditions\": [\n {\n \"displayName\":\"SLO burn rate alert for ${SLO_ID} exceeds 2\",\n \"conditionThreshold\": {\n \"filter\": DATA_RETRIEVAL_FILTER_FOR_SLO,\n \"comparison\":\"COMPARISON_GT\",\n \"thresholdValue\": 2,\n \"duration\": {\n \"seconds\":\"0\",\n },\n },\n }\n ],\n```\n\n\u003cbr /\u003e\n\nTo set the `filter` field, you need the resource name of a specific SLO. This\nvalue is of the form\n`projects/${PROJECT}/services/${SERVICE_ID}/serviceLevelObjectives/${SLO_ID}`.\nFor information on finding the SLO ID, see [Listing SLOs](/stackdriver/docs/solutions/slo-monitoring/api/using-api#slos-list).\n\nTo create an alert on burn rate, use the time-series selector\n`select_slo_burn_rate`. This selector takes two values, the target SLO\nand the lookback period. For more information, see\n[`select_slo_burn_rate`](/stackdriver/docs/solutions/slo-monitoring/api/timeseries-selectors#tss-burn-rate).\n\nFor example, the following filter gets the burn rate of the target SLO with a\n1-hour lookback period:\n\n`\"filter\":\"select_slo_burn_rate(\\\"projects/${PROJECT}/services/${SERVICE_ID}/serviceLevelObjectives/${SLO_ID}\\\", \\\"60m\\\")\"`\n\nThe rest of the alerting policy\n-------------------------------\n\nTo complete the alerting policy, specify values for the remaining fields:\n\n- `displayName`: A description of the alerting policy.\n- `combiner`: Describes the logic for combining conditions. This policy has only one condition, so either `AND` or `OR` works.\n- `notificationChannels`: An array of existing notification channels to use when the alerting policy is triggered. For information on finding and creating notification channels, see [Notification channels](/monitoring/alerts/using-channels-api#nc).\n- `documentation`: Information that is sent when the condition is violated to help recipients diagnose the problem. For details, see [`Documentation`](/monitoring/api/ref_v3/rest/v3/projects.alertPolicies#Documentation).\n\nCreating the alerting policy\n----------------------------\n\nThe following example uses the API to create a burn-rate alerting policy.\nFor information about listing, modifying, and deleting alerting policies,\nsee [Managing alerting policies by API](/monitoring/alerts/using-alerting-api). \n\n### Protocol\n\nTo create the alerting policy by using `curl`, send a `POST` message to the `https://monitoring.googleapis.com/v3/projects/${PROJECT_ID}/alertPolicies` endpoint, and provide the alerting policy in the request body. The JSON in the request body describes an alerting policy that uses a threshold condition based on the `select_slo_burn_rate` time-series selector with a one-hour lookback period.\n\n\u003cbr /\u003e\n\n1. Create a variable to hold the request body:\n\n CREATE_ALERT_POST_BODY=$(cat \u003c\u003cEOF\n {\n \"displayName\":\"SLO burn-rate alert for ${SLO_ID} with a threshold of 2\",\n \"combiner\":\"AND\",\n \"conditions\": [\n {\n \"displayName\":\"SLO burn rate alert for ${SLO_ID} exceeds 2\",\n \"conditionThreshold\": {\n \"filter\":\"select_slo_burn_rate(\\\"projects/${PROJECT}/services/${SERVICE_ID}/serviceLevelObjectives/${SLO_ID}\\\", \\\"60m\\\")\",\n \"comparison\":\"COMPARISON_GT\",\n \"thresholdValue\": 2,\n \"duration\": {\n \"seconds\":\"0\",\n },\n },\n }\n ],\n \"notificationChannels\": [\"${NOTIFICATION_CHANNEL}\", ],\n \"documentation\": {\n \"content\": \"SLO burn for the past 60m exceeded twice the acceptable budget burn rate.\",\n \"mime_type\": \"text/markdown\",\n },\n }\n EOF\n )\n\n2. Post the request to the endpoint:\n\n curl --http1.1 --header \"Authorization: Bearer ${ACCESS_TOKEN}\" --header \"Content-Type: application/json\" -X POST -d \"${CREATE_ALERT_POST_BODY}\" https://monitoring.googleapis.com/v3/projects/${PROJECT_ID}/alertPolicies\n\n\u003cbr /\u003e"]]