Creates an alert rule for a metric of a resource.

This topic provides an example of how to create a threshold-triggered alert rule for the cpu_total metric of the i-uf6j91r34rnwawoo**** instance in the acs_ecs_dashboard cloud service. The response indicates that the alert group of the alert rule is ECS_Group, the name of the alert rule is test123, and the ID of the alert rule is a151cd6023eacee2f0978e03863cc1697c89508****. The statistical method is Average, the comparison operator is GreaterThanOrEqualToThreshold, the threshold is 90, and the consecutive number of times for which the metric value is measured before a critical-level alert is triggered is 3 for critical-level alerts.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes PutResourceMetricRule

The operation that you want to perform. Set the value to PutResourceMetricRule.

ContactGroups String Yes ECS_Group

The alert group. The alert notifications of the application group are sent to the contacts that belong to the alert group.

Note An alert group includes one or more alert contacts. For more information about how to create contacts and alert groups, see PutContact and PutContactGroup.
MetricName String Yes cpu_total

The name of the metric. For more information about how to query metric names, see Appendix 1: Metrics.

Namespace String Yes acs_ecs_dashboard

The namespace of the cloud service. For more information about how to query the namespaces of cloud services, see Appendix 1: Metrics.

Resources String Yes [{"instanceId":"i-uf6j91r34rnwawoo****"}]

The information about the resource. Example: [{"instanceId":"i-uf6j91r34rnwawoo****"}] or [{"userId":"100931896542****"}].

For more information about the supported dimensions used to query resources, see Appendix 1: Metrics.

RuleId String Yes a151cd6023eacee2f0978e03863cc1697c89508****

The ID of the alert rule. For more information about how to query alert rule IDs, see DescribeMetricRuleList.

RuleName String Yes test123

The name of the alert rule. For more information about how to query alert rule names, see DescribeMetricRuleList.

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 notifications are not repeatedly sent for an alert. 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.
Interval String No 60

The interval at which the alert is triggered. Unit: seconds.

Note For more information about how to query the statistical periods of metrics, see Appendix 1: Metrics.
EmailSubject String No Alert for an ECS instance

The subject of the alert notification email.

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 metrics is collected.

Note For more information about how to query the statistical periods of metrics, see Appendix 1: Metrics.
Escalations.Critical.Statistics String No Average

The statistical method for critical-level alerts. Valid values:

  • Maximum: the maximum value
  • Minimum: the minimum value
  • Average: the average value
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 comparison operator of the threshold for critical-level alerts. Valid values:

  • GreaterThanOrEqualToThreshold
  • GreaterThanThreshold
  • LessThanOrEqualToThreshold
  • LessThanThreshold
  • NotEqualToThreshold
  • GreaterThanYesterday
  • LessThanYesterday
  • GreaterThanLastWeek
  • LessThanLastWeek
  • GreaterThanLastPeriod
  • LessThanLastPeriod
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 is measured 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 method for warn-level alerts. Valid values:

  • Maximum: the maximum value
  • Minimum: the minimum value
  • Average: the average value
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 comparison operator of the threshold for warn-level alerts. Valid values:

  • GreaterThanOrEqualToThreshold
  • GreaterThanThreshold
  • LessThanOrEqualToThreshold
  • LessThanThreshold
  • NotEqualToThreshold
  • GreaterThanYesterday
  • LessThanYesterday
  • GreaterThanLastWeek
  • LessThanLastWeek
  • GreaterThanLastPeriod
  • LessThanLastPeriod
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 is measured 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 method for info-level alerts. Valid values:

  • Maximum: the maximum value
  • Minimum: the minimum value
  • Average: the average value
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 comparison operator of the threshold for info-level alerts. Valid values:

  • GreaterThanOrEqualToThreshold
  • GreaterThanThreshold
  • LessThanOrEqualToThreshold
  • LessThanThreshold
  • NotEqualToThreshold
  • GreaterThanYesterday
  • LessThanYesterday
  • GreaterThanLastWeek
  • LessThanLastWeek
  • GreaterThanLastPeriod
  • LessThanLastPeriod
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 is measured 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.

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 value 200 indicates that the call was successful.
Message String The request processing has failed due to some unknown error.

The returned message.

RequestId String 65D50468-ECEF-48F1-A6E1-D952E89D9436

The ID of the request.

Success Boolean true

Indicates whether the call was successful. Valid values:

  • true: The call was successful.
  • false: The call failed.

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 response

XML format

<PutResourceMetricRuleResponse>
	  <Code>200</Code>
	  <Message></Message>
	  <RequestId>65D50468-ECEF-48F1-A6E1-D952E89D9436</RequestId>
	  <Success>true</Success>
</PutResourceMetricRuleResponse>

JSON format

{
   "Code":"200",
   "Message":"",
   "RequestId":"65D50468-ECEF-48F1-A6E1-D952E89D9436",
   "Success":true   
}

Error codes

For a list of error codes, visit the API Error Center.