Creates multiple alert rules for the specified metric of a specified 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 | PutResourceMetricRules | The operation that you want to perform. Set the value to PutResourceMetricRules. |
Rules.N.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. |
Rules.N.MetricName | String | No | cpu_total | The name of the metric. Valid values of N: 1 to 500. For information about how to query the name of a metric, see Appendix 1: Metrics. |
Rules.N.Escalations.Warn.Threshold | String | No | 90 | The threshold for Warn-level alerts. Valid values of N: 1 to 500. 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. |
Rules.N.EffectiveInterval | String | No | 00:00-23:59 | The time period during which the alert rule is effective. Valid values of N: 1 to 500. |
Rules.N.NoEffectiveInterval | String | No | 00:00-06:00 | The time period during which the alert rule is ineffective. Valid values of N: 1 to 500. |
Rules.N.RuleId | String | Yes | a151cd6023eacee2f0978e03863cc1697c89508**** | The ID of the alert rule. Valid values of N: 1 to 500. 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. |
Rules.N.Escalations.Critical.Times | Integer | No | 3 | The consecutive number of times for which the metric value meets the alert condition before a Critical-level alert is triggered. Valid values of N: 1 to 500. 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. |
Rules.N.Escalations.Critical.Threshold | String | No | 90 | The threshold for Critical-level alerts. Valid values of N: 1 to 500. 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. |
Rules.N.Escalations.Critical.Statistics | String | No | Average | The statistical methods for Critical-level alerts. Valid values of N: 1 to 500. The value of this parameter is determined by the 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. |
Rules.N.Escalations.Warn.ComparisonOperator | String | No | GreaterThanOrEqualToThreshold | The operator that is used to compare the metric value with the threshold for Warn-level alerts. Valid values:
Valid values of N: 1 to 500. 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. |
Rules.N.Escalations.Info.Times | Integer | No | 3 | The consecutive number of times for which the metric value meets the alert condition before an Info-level alert is triggered. Valid values of N: 1 to 500. 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. |
Rules.N.Resources | String | Yes | [{"instanceId":"i-uf6j91r34rnwawoo****"}] | The information about the resource. Examples: Valid values of N: 1 to 500. For more information about the supported dimensions that are used to query resources, see Appendix 1: Metrics. |
Rules.N.SilenceTime | Integer | No | 86400 | The mute period during which new alert notifications are not sent even if the trigger conditions are met. Unit: seconds. Default value: 86400. Valid values of N: 1 to 500. Note If an alert is not cleared after the mute period ends, CloudMonitor resends an alert notification. |
Rules.N.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. Valid values of N: 1 to 500. |
Rules.N.ContactGroups | String | Yes | ECS_Group | The alert contact groups. The alert notifications are sent to the alert contacts in the alert contact group. Valid values of N: 1 to 500. 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. |
Rules.N.Namespace | String | Yes | acs_ecs_dashboard | The namespace of the cloud service. Valid values of N: 1 to 500. For information about how to query the namespace of a cloud service, see Appendix 1: Metrics. |
Rules.N.EmailSubject | String | No | Alert for an ECS instance | The subject of the alert notification email. Valid values of N: 1 to 500. |
Rules.N.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. Valid values of N: 1 to 500. Note For information about how to query the statistical period of a metric, see Appendix 1: Metrics. |
Rules.N.RuleName | String | Yes | test123 | The name of the alert rule. Valid values of N: 1 to 500. 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. |
Rules.N.Escalations.Info.Statistics | String | No | Average | The statistical methods for Info-level alerts. Valid values of N: 1 to 500. The value of this parameter is determined by the 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. |
Rules.N.Escalations.Warn.Times | Integer | No | 3 | The consecutive number of times for which the metric value meets the alert condition before a Warn-level alert is triggered. Valid values of N: 1 to 500. 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. |
Rules.N.Escalations.Info.ComparisonOperator | String | No | GreaterThanOrEqualToThreshold | The comparison operator of the threshold for Info-level alerts. Valid values:
Valid values of N: 1 to 500. 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. |
Rules.N.Interval | String | No | 60 | The interval at which alerts are triggered based on the alert rule. Unit: seconds. Valid values of N: 1 to 500. Note For information about how to query the statistical period of a metric, see Appendix 1: Metrics. |
Rules.N.Escalations.Critical.ComparisonOperator | String | No | GreaterThanOrEqualToThreshold | The operator that is used to compare the metric value with the threshold for Critical-level alerts. Valid values:
Valid values of N: 1 to 500. 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. |
Rules.N.Escalations.Warn.Statistics | String | No | Average | The statistical methods for Warn-level alerts. Valid values of N: 1 to 500. The value of this parameter is determined by the 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. |
Rules.N.NoDataPolicy | String | No | KEEP_LAST_STATE | The method that is used to handle alerts when no monitoring data is found. Valid values:
Valid values of N: 1 to 500. |
Rules.N.Labels.N.Key | String | No | tagKey1 | The tag key. |
Rules.N.Labels.N.Value | String | No | ECS | The tag value. 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 | 15D1440E-BF24-5A41-93E4-36864635179E | The ID of the request. |
Success | Boolean | true | Indicates whether the call is successful. Valid values:
|
FailedListResult | Array of Target | The alert rules that fail to be created for the resource. |
|
Target | |||
RuleId | String | a151cd6023eacee2f0978e03863cc1697c89508**** | The ID of the alert rule. |
Result | Object | The alert rule that fails to be created. |
|
Code | String | 404 | The status code. |
Message | String | The request processing has failed due to some unknown error. | The error message. |
Success | Boolean | false | Indicates whether the call is successful. Valid values:
|
Examples
Sample requests
http(s)://[Endpoint]/?Action=PutResourceMetricRules
&Rules.1.ContactGroups=ECS_Group
&Rules.1.MetricName=cpu_total
&Rules.1.Namespace=acs_ecs_dashboard
&Rules.1.Resources=[{"instanceId":"i-uf6j91r34rnwawoo****"}]
&Rules.1.RuleId=a151cd6023eacee2f0978e03863cc1697c89508****
&Rules.1.RuleName=test123
&Rules.1.Escalations.Critical.Statistics=Average
&Rules.1.Escalations.Critical.ComparisonOperator=GreaterThanOrEqualToThreshold
&Rules.1.Escalations.Critical.Threshold=90
&Rules.1.Escalations.Critical.Times=3
&<Common request parameters>
Sample success responses
XML
format
HTTP/1.1 200 OK
Content-Type:application/xml
<PutResourceMetricRulesResponse>
<Message></Message>
<RequestId>15D1440E-BF24-5A41-93E4-36864635179E</RequestId>
<FailedListResult></FailedListResult>
<Code>200</Code>
<Success>true</Success>
</PutResourceMetricRulesResponse>
JSON
format
HTTP/1.1 200 OK
Content-Type:application/json
{
"Message" : "",
"RequestId" : "15D1440E-BF24-5A41-93E4-36864635179E",
"FailedListResult" : {
"Target" : [ ]
},
"Code" : "200",
"Success" : true
}
Error codes
For a list of error codes, visit the API Error Center.