Creates multiple alert rules for the specified metric of a specified resource.

This topic provides an example on how to create a threshold-triggered alert rule for the cpu_total metric of the i-uf6j91r34rnwawoo**** instance that belongs to Elastic Compute Service (ECS). The namespace of ECS is acs_ecs_dashboard. In this example, the alert contact 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 for Critical-level alerts is Average, the comparison operator for Critical-level alerts is GreaterThanOrEqualToThreshold, the threshold for Critical-level alerts is 90, and the consecutive number of times for which the metric value is measured before a Critical-level alert is triggered is 3.

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 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 set a collection of the Rules.N.Escalations.Critical.Statistics, Rules.N.Escalations.Critical.ComparisonOperator, Rules.N.Escalations.Critical.Threshold, and Rules.N.Escalations.Critical.Times parameters, a collection of the Rules.N.Escalations.Warn.Statistics, Rules.N.Escalations.Warn.ComparisonOperator, Rules.N.Escalations.Warn.Threshold, and Rules.N.Escalations.Warn.Times parameters, or a collection of the Rules.N.Escalations.Info.Statistics, Rules.N.Escalations.Info.ComparisonOperator, Rules.N.Escalations.Info.Threshold, and Rules.N.Escalations.Info.Times parameters.
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 set a collection of the Rules.N.Escalations.Critical.Statistics, Rules.N.Escalations.Critical.ComparisonOperator, Rules.N.Escalations.Critical.Threshold, and Rules.N.Escalations.Critical.Times parameters, a collection of the Rules.N.Escalations.Warn.Statistics, Rules.N.Escalations.Warn.ComparisonOperator, Rules.N.Escalations.Warn.Threshold, and Rules.N.Escalations.Warn.Times parameters, or a collection of the Rules.N.Escalations.Info.Statistics, Rules.N.Escalations.Info.ComparisonOperator, Rules.N.Escalations.Info.Threshold, and Rules.N.Escalations.Info.Times parameters.
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, you create a threshold-triggered alert rule.
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 set a collection of the Rules.N.Escalations.Critical.Statistics, Rules.N.Escalations.Critical.ComparisonOperator, Rules.N.Escalations.Critical.Threshold, and Rules.N.Escalations.Critical.Times parameters, a collection of the Rules.N.Escalations.Warn.Statistics, Rules.N.Escalations.Warn.ComparisonOperator, Rules.N.Escalations.Warn.Threshold, and Rules.N.Escalations.Warn.Times parameters, or a collection of the Rules.N.Escalations.Info.Statistics, Rules.N.Escalations.Info.ComparisonOperator, Rules.N.Escalations.Info.Threshold, and Rules.N.Escalations.Info.Times parameters.
Rules.N.Escalations.Critical.Threshold String No 90

The threshold for Critical-level alerts.

Valid values of N: 1 to 500.

Note You must set a collection of the Rules.N.Escalations.Critical.Statistics, Rules.N.Escalations.Critical.ComparisonOperator, Rules.N.Escalations.Critical.Threshold, and Rules.N.Escalations.Critical.Times parameters, a collection of the Rules.N.Escalations.Warn.Statistics, Rules.N.Escalations.Warn.ComparisonOperator, Rules.N.Escalations.Warn.Threshold, and Rules.N.Escalations.Warn.Times parameters, or a collection of the Rules.N.Escalations.Info.Statistics, Rules.N.Escalations.Info.ComparisonOperator, Rules.N.Escalations.Info.Threshold, and Rules.N.Escalations.Info.Times parameters.
Rules.N.Escalations.Critical.Statistics String No Average

The statistical methods for Critical-level alerts. Valid values:

  • Maximum: the maximum value
  • Minimum: the minimum value
  • Average: the average value
  • Availability: the availability rate

Valid values of N: 1 to 500.

Note You must set a collection of the Rules.N.Escalations.Critical.Statistics, Rules.N.Escalations.Critical.ComparisonOperator, Rules.N.Escalations.Critical.Threshold, and Rules.N.Escalations.Critical.Times parameters, a collection of the Rules.N.Escalations.Warn.Statistics, Rules.N.Escalations.Warn.ComparisonOperator, Rules.N.Escalations.Warn.Threshold, and Rules.N.Escalations.Warn.Times parameters, or a collection of the Rules.N.Escalations.Info.Statistics, Rules.N.Escalations.Info.ComparisonOperator, Rules.N.Escalations.Info.Threshold, and Rules.N.Escalations.Info.Times parameters.
Rules.N.Escalations.Warn.ComparisonOperator String No GreaterThanOrEqualToThreshold

The comparison operator that is used to compare the metric value with the threshold. Valid values:

  • GreaterThanOrEqualToThreshold: greater than or equal to the threshold
  • GreaterThanThreshold: greater than the threshold
  • LessThanOrEqualToThreshold: less than or equal to the threshold
  • LessThanThreshold: less than the threshold
  • NotEqualToThreshold: not equal to the threshold
  • GreaterThanYesterday: greater than the metric value at the same time yesterday
  • LessThanYesterday: less than the metric value at the same time yesterday
  • GreaterThanLastWeek: greater than the metric value at the same time last week
  • LessThanLastWeek: less than the metric value at the same time last week
  • GreaterThanLastPeriod: greater than the metric value in the last monitoring cycle
  • LessThanLastPeriod: less than the metric value in the last monitoring cycle

Valid values of N: 1 to 500.

Note You must set a collection of the Rules.N.Escalations.Critical.Statistics, Rules.N.Escalations.Critical.ComparisonOperator, Rules.N.Escalations.Critical.Threshold, and Rules.N.Escalations.Critical.Times parameters, a collection of the Rules.N.Escalations.Warn.Statistics, Rules.N.Escalations.Warn.ComparisonOperator, Rules.N.Escalations.Warn.Threshold, and Rules.N.Escalations.Warn.Times parameters, or a collection of the Rules.N.Escalations.Info.Statistics, Rules.N.Escalations.Info.ComparisonOperator, Rules.N.Escalations.Info.Threshold, and Rules.N.Escalations.Info.Times parameters.
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 set a collection of the Rules.N.Escalations.Critical.Statistics, Rules.N.Escalations.Critical.ComparisonOperator, Rules.N.Escalations.Critical.Threshold, and Rules.N.Escalations.Critical.Times parameters, a collection of the Rules.N.Escalations.Warn.Statistics, Rules.N.Escalations.Warn.ComparisonOperator, Rules.N.Escalations.Warn.Threshold, and Rules.N.Escalations.Warn.Times parameters, or a collection of the Rules.N.Escalations.Info.Statistics, Rules.N.Escalations.Info.ComparisonOperator, Rules.N.Escalations.Info.Threshold, and Rules.N.Escalations.Info.Times parameters.
Rules.N.Resources String Yes [{"instanceId":"i-uf6j91r34rnwawoo****"}]

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

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 alerts 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 group. 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, you create a threshold-triggered alert rule.
Rules.N.Escalations.Info.Statistics String No Average

The statistical methods for Info-level alerts. Valid values:

  • Maximum: the maximum value
  • Minimum: the minimum value
  • Average: the average value
  • Availability: the availability rate

Valid values of N: 1 to 500.

Note You must set a collection of the Rules.N.Escalations.Critical.Statistics, Rules.N.Escalations.Critical.ComparisonOperator, Rules.N.Escalations.Critical.Threshold, and Rules.N.Escalations.Critical.Times parameters, a collection of the Rules.N.Escalations.Warn.Statistics, Rules.N.Escalations.Warn.ComparisonOperator, Rules.N.Escalations.Warn.Threshold, and Rules.N.Escalations.Warn.Times parameters, or a collection of the Rules.N.Escalations.Info.Statistics, Rules.N.Escalations.Info.ComparisonOperator, Rules.N.Escalations.Info.Threshold, and Rules.N.Escalations.Info.Times parameters.
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 set a collection of the Rules.N.Escalations.Critical.Statistics, Rules.N.Escalations.Critical.ComparisonOperator, Rules.N.Escalations.Critical.Threshold, and Rules.N.Escalations.Critical.Times parameters, a collection of the Rules.N.Escalations.Warn.Statistics, Rules.N.Escalations.Warn.ComparisonOperator, Rules.N.Escalations.Warn.Threshold, and Rules.N.Escalations.Warn.Times parameters, or a collection of the Rules.N.Escalations.Info.Statistics, Rules.N.Escalations.Info.ComparisonOperator, Rules.N.Escalations.Info.Threshold, and Rules.N.Escalations.Info.Times parameters.
Rules.N.Escalations.Info.ComparisonOperator String No GreaterThanOrEqualToThreshold

The comparison operator that is used to compare the metric value with the threshold. Valid values:

  • GreaterThanOrEqualToThreshold: greater than or equal to the threshold
  • GreaterThanThreshold: greater than the threshold
  • LessThanOrEqualToThreshold: less than or equal to the threshold
  • LessThanThreshold: less than the threshold
  • NotEqualToThreshold: not equal to the threshold
  • GreaterThanYesterday: greater than the metric value at the same time yesterday
  • LessThanYesterday: less than the metric value at the same time yesterday
  • GreaterThanLastWeek: greater than the metric value at the same time last week
  • LessThanLastWeek: less than the metric value at the same time last week
  • GreaterThanLastPeriod: greater than the metric value in the last monitoring cycle
  • LessThanLastPeriod: less than the metric value in the last monitoring cycle

Valid values of N: 1 to 500.

Note You must set a collection of the Rules.N.Escalations.Critical.Statistics, Rules.N.Escalations.Critical.ComparisonOperator, Rules.N.Escalations.Critical.Threshold, and Rules.N.Escalations.Critical.Times parameters, a collection of the Rules.N.Escalations.Warn.Statistics, Rules.N.Escalations.Warn.ComparisonOperator, Rules.N.Escalations.Warn.Threshold, and Rules.N.Escalations.Warn.Times parameters, or a collection of the Rules.N.Escalations.Info.Statistics, Rules.N.Escalations.Info.ComparisonOperator, Rules.N.Escalations.Info.Threshold, and Rules.N.Escalations.Info.Times parameters.
Rules.N.Interval String No 60

The interval at which the alert rule is executed.

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 comparison operator that is used to compare the metric value with the threshold. Valid values:

  • GreaterThanOrEqualToThreshold: greater than or equal to the threshold
  • GreaterThanThreshold: greater than the threshold
  • LessThanOrEqualToThreshold: less than or equal to the threshold
  • LessThanThreshold: less than the threshold
  • NotEqualToThreshold: not equal to the threshold
  • GreaterThanYesterday: greater than the metric value at the same time yesterday
  • LessThanYesterday: less than the metric value at the same time yesterday
  • GreaterThanLastWeek: greater than the metric value at the same time last week
  • LessThanLastWeek: less than the metric value at the same time last week
  • GreaterThanLastPeriod: greater than the metric value in the last monitoring cycle
  • LessThanLastPeriod: less than the metric value in the last monitoring cycle

Valid values of N: 1 to 500.

Note You must set a collection of the Rules.N.Escalations.Critical.Statistics, Rules.N.Escalations.Critical.ComparisonOperator, Rules.N.Escalations.Critical.Threshold, and Rules.N.Escalations.Critical.Times parameters, a collection of the Rules.N.Escalations.Warn.Statistics, Rules.N.Escalations.Warn.ComparisonOperator, Rules.N.Escalations.Warn.Threshold, and Rules.N.Escalations.Warn.Times parameters, or a collection of the Rules.N.Escalations.Info.Statistics, Rules.N.Escalations.Info.ComparisonOperator, Rules.N.Escalations.Info.Threshold, and Rules.N.Escalations.Info.Times parameters.
Rules.N.Escalations.Warn.Statistics String No Average

The statistical methods for Warn-level alerts. Valid values:

  • Maximum: the maximum value
  • Minimum: the minimum value
  • Average: the average value
  • Availability: the availability rate

Valid values of N: 1 to 500.

Note You must set a collection of the Rules.N.Escalations.Critical.Statistics, Rules.N.Escalations.Critical.ComparisonOperator, Rules.N.Escalations.Critical.Threshold, and Rules.N.Escalations.Critical.Times parameters, a collection of the Rules.N.Escalations.Warn.Statistics, Rules.N.Escalations.Warn.ComparisonOperator, Rules.N.Escalations.Warn.Threshold, and Rules.N.Escalations.Warn.Times parameters, or a collection of the Rules.N.Escalations.Info.Statistics, Rules.N.Escalations.Info.ComparisonOperator, Rules.N.Escalations.Info.Threshold, and Rules.N.Escalations.Info.Times parameters.
Rules.N.NoDataPolicy String No KEEP_LAST_STATE

The method that is used to handle alerts when no monitoring data is found. Valid values:

  • KEEP_LAST_STATE (default value): No operation is performed.
  • INSUFFICIENT_DATA: An alert whose content is "Insufficient data" is triggered.
  • OK: The status is considered normal.

Valid values of N: 1 to 500.

Rules.N.Labels.N.Key String No tagKey1

The key of the tag.

Rules.N.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 was 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 was successful. Valid values:

  • true: The call was successful.
  • false: The call failed.
FailedListResult Array of Target

The alert rules that failed to be created for the resource.

Target
RuleId String a151cd6023eacee2f0978e03863cc1697c89508****

The ID of the alert rule.

Result Object

The alert rule that failed to be created.

Code String 404

The HTTP status code.

Message String The request processing has failed due to some unknown error.

The error message.

Success Boolean false

Indicates whether the call was successful. Valid values:

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

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.