Creates an alert rule for a metric of a resource.
This topic provides an example to show how to create a threshold-triggered alert rule
for the cpu_total
metric of an Elastic Compute Service (ECS) instance whose ID is i-uf6j91r34rnwawoo****
. The namespace of ECS is acs_ecs_dashboard
. The alert contact group of the alert rule is ECS_Group
. The name of the alert rule is test123
. The ID of the alert rule is a151cd6023eacee2f0978e03863cc1697c89508****
. The statistical method for Critical-level alerts is Average
. The comparison operator for Critical-level alerts is GreaterThanOrEqualToThreshold
. The threshold for Critical-level alerts is 90
. The consecutive number of times for which the metric value meets the trigger condition
before a Critical-level alert is triggered is 3
.
Debugging
Request parameters
Parameter | Type | Required | Example | Description |
---|---|---|---|---|
Action | String | Yes | PutResourceMetricRule |
The operation that you want to perform. Set the value to PutResourceMetricRule. |
RuleId | String | Yes | a151cd6023eacee2f0978e03863cc1697c89508**** |
The ID of the alert rule. You can specify a new ID or the ID of an existing alert rule. For information about how to query the ID of an alert rule, see DescribeMetricRuleList. Note If you specify a new ID, a threshold-triggered alert rule is created.
|
RuleName | String | Yes | test123 |
The name of the alert rule. You can specify a new name or the name of an existing alert rule. For information about how to query the name of an alert rule, see DescribeMetricRuleList. Note If you specify a new name, a threshold-triggered alert rule is created.
|
Namespace | String | Yes | acs_ecs_dashboard |
The namespace of the cloud service. For information about how to query the namespace of a cloud service, see Appendix 1: Metrics. Note If you create a Prometheus alert rule for Hybrid Cloud Monitoring, you must set this
parameter to
acs_prometheus .
|
MetricName | String | Yes | cpu_total |
The name of the metric. For information about how to query the name of a metric, see Appendix 1: Metrics. Note If you create a Prometheus alert rule for Hybrid Cloud Monitoring, you must set this
parameter to the name of the namespace. For information about how to obtain the name
of a namespace, see DescribeHybridMonitorNamespaceList.
|
Resources | String | Yes | [{"instanceId":"i-uf6j91r34rnwawoo****"}] |
The information about the resource. Examples: For information about the supported dimensions that are used to query resources, see Appendix 1: Metrics. |
ContactGroups | String | Yes | ECS_Group |
The alert contact group. The alert notifications are sent to the contacts that belong to the alert contact group. Note An alert contact group can contain one or more alert contacts. For information about
how to create alert contacts and alert contact groups, see PutContact and PutContactGroup.
|
Webhook | String | No | https://alert.aliyun.com.com:8080/callback |
The callback URL to which a POST request is sent when an alert is triggered based on the alert rule. |
EffectiveInterval | String | No | 00:00-23:59 |
The time period during which the alert rule is effective. |
NoEffectiveInterval | String | No | 00:00-06:00 |
The time period during which the alert rule is ineffective. |
SilenceTime | Integer | No | 86400 |
The mute period during which new alerts are not sent even if the trigger conditions are met. Unit: seconds. Default value: 86400. Note If an alert is not cleared within the mute period, a new alert notification is sent
when the mute period ends.
|
Period | String | No | 60 |
The statistical period of the metric. Unit: seconds. The default value is the interval at which the monitoring data of the metric is collected. Note For information about how to query the statistical period of a metric, see Appendix 1: Metrics.
|
Interval | String | No | 60 |
The interval at which the alert is triggered. Unit: seconds. Note For information about how to query the statistical period of a metric, see Appendix 1: Metrics.
|
EmailSubject | String | No | Alert for an ECS instance |
The subject of the alert notification email. |
Escalations.Critical.Statistics | String | No | Average |
The statistical methods for Critical-level alerts. Valid values:
Note You must select at least one of the Critical, Warn, and Info alert levels and specify
the Statistics, ComparisonOperator, Threshold, and Times parameters for the selected
alert level.
|
Escalations.Critical.ComparisonOperator | String | No | GreaterThanOrEqualToThreshold |
The operator that is used to compare the metric value with the threshold. Valid values:
Note You must select at least one of the Critical, Warn, and Info alert levels and specify
the Statistics, ComparisonOperator, Threshold, and Times parameters for the selected
alert level.
|
Escalations.Critical.Threshold | String | No | 90 |
The threshold for Critical-level alerts. Note You must select at least one of the Critical, Warn, and Info alert levels and specify
the Statistics, ComparisonOperator, Threshold, and Times parameters for the selected
alert level.
|
Escalations.Critical.Times | Integer | No | 3 |
The consecutive number of times for which the metric value meets the trigger condition before a Critical-level alert is triggered. Note You must select at least one of the Critical, Warn, and Info alert levels and specify
the Statistics, ComparisonOperator, Threshold, and Times parameters for the selected
alert level.
|
Escalations.Warn.Statistics | String | No | Average |
The statistical methods for Warn-level alerts. Valid values:
Note You must select at least one of the Critical, Warn, and Info alert levels and specify
the Statistics, ComparisonOperator, Threshold, and Times parameters for the selected
alert level.
|
Escalations.Warn.ComparisonOperator | String | No | GreaterThanOrEqualToThreshold |
The operator that is used to compare the metric value with the threshold. Valid values:
Note You must select at least one of the Critical, Warn, and Info alert levels and specify
the Statistics, ComparisonOperator, Threshold, and Times parameters for the selected
alert level.
|
Escalations.Warn.Threshold | String | No | 90 |
The threshold for Warn-level alerts. Note You must select at least one of the Critical, Warn, and Info alert levels and specify
the Statistics, ComparisonOperator, Threshold, and Times parameters for the selected
alert level.
|
Escalations.Warn.Times | Integer | No | 3 |
The consecutive number of times for which the metric value meets the trigger condition before a Warn-level alert is triggered. Note You must select at least one of the Critical, Warn, and Info alert levels and specify
the Statistics, ComparisonOperator, Threshold, and Times parameters for the selected
alert level.
|
Escalations.Info.Statistics | String | No | Average |
The statistical methods for Info-level alerts. Valid values:
Note You must select at least one of the Critical, Warn, and Info alert levels and specify
the Statistics, ComparisonOperator, Threshold, and Times parameters for the selected
alert level.
|
Escalations.Info.ComparisonOperator | String | No | GreaterThanOrEqualToThreshold |
The operator that is used to compare the metric value with the threshold. Valid values:
Note You must select at least one of the Critical, Warn, and Info alert levels and specify
the Statistics, ComparisonOperator, Threshold, and Times parameters for the selected
alert level.
|
Escalations.Info.Threshold | String | No | 90 |
The threshold for Info-level alerts. Note You must select at least one of the Critical, Warn, and Info alert levels and specify
the Statistics, ComparisonOperator, Threshold, and Times parameters for the selected
alert level.
|
Escalations.Info.Times | Integer | No | 3 |
The consecutive number of times for which the metric value meets the trigger condition before an Info-level alert is triggered. Note You must select at least one of the Critical, Warn, and Info alert levels and specify
the Statistics, ComparisonOperator, Threshold, and Times parameters for the selected
alert level.
|
NoDataPolicy | String | No | KEEP_LAST_STATE |
The processing method of alerts when no monitoring data is found. Valid values:
|
CompositeExpression | Object | No |
The trigger conditions for multiple metrics. Note The trigger conditions for a single metric and multiple metrics are mutually exclusive.
You cannot specify trigger conditions for a single metric and multiple metrics at
the same time.
|
|
ExpressionList | Array | No |
The trigger conditions that are created in standard mode. |
|
MetricName | String | No | cpu_total |
The metric that is used to monitor the cloud service. |
ComparisonOperator | String | No | GreaterThanOrEqualToThreshold |
The operator that is used to compare the metric value with the threshold. Valid values:
|
Period | Long | No | 60 |
The aggregation period of the metric. Unit: seconds. |
Statistics | String | No | $Maximum |
The statistical method of the metric. Valid values:
Note
$ is the prefix of the metric. For information about the Alibaba Cloud services that
are supported by CloudMonitor, see Appendix 1: Metrics.
|
Threshold | String | No | 90 |
The alert threshold. |
ExpressionListJoin | String | No | || |
The relationship between the trigger conditions for multiple metrics. Valid values:
|
ExpressionRaw | String | No | $Average > ($instanceId == 'i-io8kfvcpp7x5****'? 80: 50) |
The trigger conditions that are created by using expressions. You can use expressions to create trigger conditions in the following scenarios:
|
Level | String | No | Critical |
The level of the alert. Valid values:
|
Times | Integer | No | 3 |
The number of consecutive triggers. If the number of times that the metric values meet the trigger conditions reaches the value of this parameter, CloudMonitor sends alert notifications. |
Prometheus | Object | No |
The Prometheus alert rule. Note This parameter is required only when you create a Prometheus alert rule for Hybrid
Cloud Monitoring.
|
|
PromQL | String | No | cpuUsage{instanceId="xxxx"}[1m]>90 |
The PromQL query statement. Note The data obtained by using the PromQL query statement is the monitoring data. You
must include the alert threshold in this statement.
|
Level | String | No | Critical |
The level of the alert. Valid values:
|
Times | Integer | No | 3 |
The number of consecutive triggers. If the number of times that the metric values meet the trigger conditions reaches the value of this parameter, CloudMonitor sends alert notifications. |
Annotations | Array | No |
The annotations of the Prometheus alert rule. When a Prometheus alert is triggered, the system renders the annotated keys and values to help you understand the metrics and alert rule. Note This parameter is equivalent to the annotations parameter of open source Prometheus.
|
|
Key | String | No | summary |
The key of the annotation. |
Value | String | No | {{ $labels.instance }} CPU usage above 10% {current value: {{ humanizePercentage $value }} } |
The value of the annotation. |
Labels.N.Key | String | No | tagKey1 |
The key of the tag. |
Labels.N.Value | String | No | ECS |
The value of the tag. Note You can use a template parameter to specify a tag value. CloudMonitor replaces the
value of the template parameter with an actual tag value.
|
For more information about common request parameters, see Common parameters.
Response parameters
Parameter | Type | Example | Description |
---|---|---|---|
Code | String | 200 |
The HTTP status code. Note The status code 200 indicates that the call is successful.
|
Message | String | The request processing has failed due to some unknown error. |
The error message. |
RequestId | String | 65D50468-ECEF-48F1-A6E1-D952E89D9436 |
The ID of the request. |
Success | Boolean | true |
Indicates whether the call is successful. Valid values:
|
Examples
Sample requests
http(s)://[Endpoint]/?Action=PutResourceMetricRule
&ContactGroups=ECS_Group
&MetricName=cpu_total
&Namespace=acs_ecs_dashboard
&Resources=[{"instanceId":"i-uf6j91r34rnwawoo****"}]
&RuleId=a151cd6023eacee2f0978e03863cc1697c89508****
&RuleName=test123
&Escalations.Critical.Statistics=Average
&Escalations.Critical.ComparisonOperator=GreaterThanOrEqualToThreshold
&Escalations.Critical.Threshold=90
&Escalations.Critical.Times=3
&<Common request parameters>
Sample success responses
XML
format
HTTP/1.1 200 OK
Content-Type:application/xml
<PutResourceMetricRuleResponse>
<Code>200</Code>
<Message></Message>
<RequestId>65D50468-ECEF-48F1-A6E1-D952E89D9436</RequestId>
<Success>true</Success>
</PutResourceMetricRuleResponse>
JSON
format
HTTP/1.1 200 OK
Content-Type:application/json
{
"Code" : "200",
"Message" : "",
"RequestId" : "65D50468-ECEF-48F1-A6E1-D952E89D9436",
"Success" : true
}
Error codes
For a list of error codes, visit the Error Center.