All Products
Search
Document Center

Cloud Monitor:PutResourceMetricRules

Last Updated:Jun 29, 2026

Calls the PutResourceMetricRules operation to create multiple threshold alert rules for a specified metric of a specified resource.

Operation description

This topic provides an example of how to create a threshold alert rule for the cpu_total metric of the Elastic Computing Service (ECS) instance i-uf6j91r34rnwawoo**** in the acs_ecs_dashboard namespace. The alert contact group is set to ECS_Group, the alert rule name is set to test123, the alert rule ID is set to a151cd6023eacee2f0978e03863cc1697c89508****, the statistics method for the Critical level is set to Average, the comparison operator for the Critical level is set to GreaterThanOrEqualToThreshold, the threshold for the Critical level is set to 90, and the retry count for the Critical level is set to 3.

Note

As of August 15, 2024, Statistics validation is added. You can set the statistics value only to the Statistics value that corresponds to the metric. For more information about how to obtain the value of this parameter, see Alibaba Cloud service monitoring metrics.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

cms:PutResourceMetricRules

create

*All Resource

*

None None

Request parameters

Parameter

Type

Required

Description

Example

Rules

array<object>

Yes

The list of threshold alert rules.

Valid values of N: 1 to 50.

array<object>

No

None.

Escalations.Info.Threshold

string

No

The threshold for Info-level alerts.

Note

You must specify at least one of the following alert levels: Critical, Warn, or Info. For the specified alert level, you must set all of the following parameters: Statistics, ComparisonOperator, Threshold, and Times.

90

MetricName

string

No

The metric name.

Valid values of N: 1 to 50.

For more information about how to query metric names, see Alibaba Cloud service monitoring metrics.

cpu_total

Escalations.Warn.Threshold

string

No

The threshold for Warn-level alerts.

Valid values of N: 1 to 50.

Note

You must specify at least one of the following alert levels: Critical, Warn, or Info. For the specified alert level, you must set all of the following parameters: Statistics, ComparisonOperator, Threshold, and Times.

90

EffectiveInterval

string

No

The effective period of the alert rule.

Valid values of N: 1 to 50.

00:00-23:59

NoEffectiveInterval

string

No

The time range during which the alert rule is ineffective.

Valid values of N: 1 to 50.

00:00-06:00

RuleId

string

Yes

The alert rule ID.

Valid values of N: 1 to 50.

You can enter a new alert rule ID or use an existing alert rule ID in CloudMonitor. For more information about how to query alert rule IDs, see DescribeMetricRuleList.

Note

If you enter a new alert rule ID, a threshold alert rule is created.

a151cd6023eacee2f0978e03863cc1697c89508****

Escalations.Critical.Times

integer

No

The retry count for Critical-level alerts.

Valid values of N: 1 to 50.

Note

You must specify at least one of the following alert levels: Critical, Warn, or Info. For the specified alert level, you must set all of the following parameters: Statistics, ComparisonOperator, Threshold, and Times.

3

Escalations.Critical.Threshold

string

No

The threshold for Critical-level alerts.

Valid values of N: 1 to 50.

Note

You must specify at least one of the following alert levels: Critical, Warn, or Info. For the specified alert level, you must set all of the following parameters: Statistics, ComparisonOperator, Threshold, and Times.

90

Escalations.Critical.Statistics

string

No

The statistics method for Critical-level alerts.

Valid values of N: 1 to 50.

The value of this parameter is determined by the Statistics column that corresponds to the MetricName of the specified Alibaba Cloud service. Examples: Maximum, Minimum, and Average. For more information about how to obtain the value of this parameter, see Alibaba Cloud service monitoring metrics.

Note

You must specify at least one of the following alert levels: Critical (critical), Warn (warning), or Info (information). For the specified alert level, you must set all of the following parameters: Statistics, ComparisonOperator, Threshold, and Times.

Average

Escalations.Warn.ComparisonOperator

string

No

The comparison operator for Warn-level alerts. 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.

  • EqualToThreshold: equal to the threshold.

  • GreaterThanYesterday: greater than the value at the same time yesterday.

  • LessThanYesterday: less than the value at the same time yesterday.

  • GreaterThanLastWeek: greater than the value at the same time last week.

  • LessThanLastWeek: less than the value at the same time last week.

  • GreaterThanLastPeriod: greater than the value in the last period.

  • LessThanLastPeriod: less than the value in the last period.

Valid values of N: 1 to 50.

Note

You must specify at least one of the following alert levels: Critical, Warn, or Info. For the specified alert level, you must set all of the following parameters: Statistics, ComparisonOperator, Threshold, and Times.

GreaterThanOrEqualToThreshold

Escalations.Info.Times

integer

No

The retry count for Info-level alerts.

Valid values of N: 1 to 50.

Note

You must specify at least one of the following alert levels: Critical, Warn, or Info. For the specified alert level, you must set all of the following parameters: Statistics, ComparisonOperator, Threshold, and Times.

3

Resources

string

Yes

The resource information, such as [{"instanceId":"i-uf6j91r34rnwawoo****"}] or [{"userId":"100931896542****"}].

Valid values of N: 1 to 50.

For more information about the supported dimensions, see Alibaba Cloud service monitoring metrics.

[{"instanceId":"i-uf6j91r34rnwawoo****"}]

SilenceTime

integer

No

The mute period.

Unit: seconds. Default value: 86400.

Valid values of N: 1 to 50.

Note

The mute period specifies the interval at which an alert notification is sent again if the alert is not cleared.

86400

Webhook

string

No

The callback URL to which a POST request is sent when an alert is triggered.

Valid values of N: 1 to 50.

https://alert.aliyun.com.com:8080/callback

ContactGroups

string

Yes

The alert contact group. Alert notifications are sent to the alert contacts in the alert contact group.

Valid values of N: 1 to 50.

Note

An alert contact group contains one or more alert contacts. For more information about how to create alert contacts and alert contact groups, see PutContact and PutContactGroup.

ECS_Group

Namespace

string

Yes

The data namespace of the Alibaba Cloud service.

Valid values of N: 1 to 50.

For more information about how to query the data namespace of an Alibaba Cloud service, see Alibaba Cloud service monitoring metrics.

acs_ecs_dashboard

EmailSubject

string

No

The subject of the alert email.

Valid values of N: 1 to 50.

ECS instance alert

Period

string

No

The statistical period of the metric.

Unit: seconds. Default value: the original reporting period of the metric.

Valid values of N: 1 to 50.

Note

For more information about how to query the statistical period of a metric, see Alibaba Cloud service monitoring metrics.

60

RuleName

string

Yes

The alert rule name.

Valid values of N: 1 to 50.

You can enter a new alert rule name or use an existing alert rule name in CloudMonitor. For more information about how to query alert rule names, see DescribeMetricRuleList.

Note

If you enter a new alert rule name, a threshold alert rule is created.

test123

Escalations.Info.Statistics

string

No

The statistics method for Info-level alerts.

Valid values of N: 1 to 50.

The value of this parameter is determined by the Statistics column that corresponds to the MetricName of the specified Alibaba Cloud service. Examples: Maximum, Minimum, and Average. For more information about how to obtain the value of this parameter, see Alibaba Cloud service monitoring metrics.

Note

You must specify at least one of the following alert levels: Critical (critical), Warn (warning), or Info (information). For the specified alert level, you must set all of the following parameters: Statistics, ComparisonOperator, Threshold, and Times.

Average

Escalations.Warn.Times

integer

No

The retry count for Warn-level alerts.

Valid values of N: 1 to 50.

Note

You must specify at least one of the following alert levels: Critical, Warn, or Info. For the specified alert level, you must set all of the following parameters: Statistics, ComparisonOperator, Threshold, and Times.

3

Escalations.Info.ComparisonOperator

string

No

The comparison operator for Info-level alerts. 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.

  • EqualToThreshold: equal to the threshold.

  • GreaterThanYesterday: greater than the value at the same time yesterday.

  • LessThanYesterday: less than the value at the same time yesterday.

  • GreaterThanLastWeek: greater than the value at the same time last week.

  • LessThanLastWeek: less than the value at the same time last week.

  • GreaterThanLastPeriod: greater than the value in the last period.

  • LessThanLastPeriod: less than the value in the last period.

Valid values of N: 1 to 50.

Note

You must specify at least one of the following alert levels: Critical, Warn, or Info. For the specified alert level, you must set all of the following parameters: Statistics, ComparisonOperator, Threshold, and Times.

GreaterThanOrEqualToThreshold

Interval

string

No

The trigger period of the alert rule.

Unit: seconds.

Valid values of N: 1 to 50.

Note

For more information about how to query the statistical period of a metric, see Alibaba Cloud service monitoring metrics.

60

Escalations.Critical.ComparisonOperator

string

No

The comparison operator for Critical-level alerts. 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.

  • EqualToThreshold: equal to the threshold.

  • GreaterThanYesterday: greater than the value at the same time yesterday.

  • LessThanYesterday: less than the value at the same time yesterday.

  • GreaterThanLastWeek: greater than the value at the same time last week.

  • LessThanLastWeek: less than the value at the same time last week.

  • GreaterThanLastPeriod: greater than the value in the last period.

  • LessThanLastPeriod: less than the value in the last period.

Valid values of N: 1 to 50.

Note

You must specify at least one of the following alert levels: Critical, Warn, or Info. For the specified alert level, you must set all of the following parameters: Statistics, ComparisonOperator, Threshold, and Times.

GreaterThanOrEqualToThreshold

Escalations.Warn.Statistics

string

No

The statistics method for Warn-level alerts.

Valid values of N: 1 to 50.

The value of this parameter is determined by the Statistics column that corresponds to the MetricName of the specified Alibaba Cloud service. Examples: Maximum, Minimum, and Average. For more information about how to obtain the value of this parameter, see Alibaba Cloud service monitoring metrics.

Note

You must specify at least one of the following alert levels: Critical (critical), Warn (warning), or Info (information). For the specified alert level, you must set all of the following parameters: Statistics, ComparisonOperator, Threshold, and Times.

Average

NoDataPolicy

string

No

The processing method when no monitoring data is found. Valid values:

  • KEEP_LAST_STATE (default): No action is taken.

  • INSUFFICIENT_DATA: An alert whose content is "Insufficient Data" is triggered.

  • OK: The status is considered normal.

Valid values of N: 1 to 50.

KEEP_LAST_STATE

Labels

array<object>

No

When the metric reaches the alert condition and an alert is triggered, the labels are written to the metric and displayed in the alert notification.

object

No

None.

Key

string

No

The label key.

tagKey1

Value

string

No

The label value.

Note

The label value supports template parameters. Template parameters are replaced with actual label values.

ECS

SendOK

boolean

No

Specifies whether to send a recovery notification.

true

For more information about common request parameters, see Common parameters.

Response elements

Element

Type

Description

Example

object

None.

Code

string

The HTTP status code.

Note

The value 200 indicates success.

200

Message

string

The error message.

The request processing has failed due to some unknown error.

RequestId

string

The request ID.

15D1440E-BF24-5A41-93E4-36864635179E

Success

boolean

Indicates whether the operation was successful. Valid values:

  • true: The operation was successful.

  • false: The operation failed.

true

FailedListResult

object

Target

array<object>

The list of failed results for setting alert rules on resources.

array<object>

None.

RuleId

string

The alert rule ID.

a151cd6023eacee2f0978e03863cc1697c89508****

Result

object

The failure result.

Code

string

The status code.

404

Message

string

The error message.

The request processing has failed due to some unknown error.

Success

boolean

Indicates whether the operation was successful. Valid values:

  • true: Successful.

  • false: Failed.

false

Examples

Success response

JSON format

{
  "Code": "200",
  "Message": "The request processing has failed due to some unknown error.",
  "RequestId": "15D1440E-BF24-5A41-93E4-36864635179E",
  "Success": true,
  "FailedListResult": {
    "Target": [
      {
        "RuleId": "a151cd6023eacee2f0978e03863cc1697c89508****",
        "Result": {
          "Code": "404",
          "Message": "The request processing has failed due to some unknown error.",
          "Success": false
        }
      }
    ]
  }
}

Error codes

HTTP status code

Error code

Error message

Description

400 %s %s
422 %s %s
499 %s %s
500 InternalError The request processing has failed due to some unknown error.
204 %s %s
403 %s %s
206 %s %s
404 %s %s
503 %s %s
406 %s %s

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.