PutResourceMetricRule

Updated at:

Sets an alert rule.

Operation description

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

Note

On August 15, 2024, Statistics validation increases. The statistical value must match the Statistics value of the corresponding metric. For more information about how to obtain the valid values 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:PutResourceMetricRule

create

*All Resource

*

None None

Request parameters

Parameter

Type

Required

Description

Example

RuleId

string

Yes

The alert rule ID.

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

Note

Entering a new alert rule ID indicates that a threshold-based alert rule is created.

a151cd6023eacee2f0978e03863cc1697c89508****

RuleName

string

Yes

The alert rule name.

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

Note

Entering a new alert rule name indicates that a threshold-based alert rule is created.

test123

Namespace

string

Yes

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

Note

When you create a Prometheus alert rule for Hybrid CloudMonitor, you must set this parameter to acs_prometheus.

acs_ecs_dashboard

MetricName

string

Yes

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

Note

When you create a Prometheus alert rule for Hybrid CloudMonitor, this parameter specifies the metric repository name. For more information about how to obtain the metric repository name, see DescribeHybridMonitorNamespaceList.

cpu_total

Resources

string

No

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

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

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

ContactGroups

string

Yes

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

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

Webhook

string

No

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

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

EffectiveInterval

string

No

The effective period of the alert rule.

00:00-23:59

NoEffectiveInterval

string

No

The period during which the alert rule is inactive.

00:00-06:00

SilenceTime

integer

No

The mute epoch. Unit: seconds. Default value: 86400.

Note

The mute epoch refers to the interval to send an alert notification again if the alert does not recover to Normal after it is triggered.

86400

Period

string

No

The statistical period of the metric. Unit: seconds. The default value is the original reporting epoch of the metric.

Note

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

60

Interval

string

No

The trigger epoch of the alert rule. Unit: seconds.

Note

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

60

EmailSubject

string

No

The subject of the alert email.

ECS instance alert

Escalations.Critical.Statistics

string

No

The statistical method for the Critical-level alert.

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

Note

You must configure at least one of the following alert levels: Critical, Warn, and Info. For the configured alert level, the Settings for the Statistics, ComparisonOperator, Threshold, and Times parameters must be specified at the same time.

Average

Escalations.Critical.ComparisonOperator

string

No

The comparison operator for the Critical-level threshold. Valid values:

  • GreaterThanOrEqualToThreshold: greater than or equal to.

  • GreaterThanThreshold: greater than.

  • LessThanOrEqualToThreshold: less than or equal to.

  • LessThanThreshold: less than.

  • NotEqualToThreshold: not equal to.

  • EqualToThreshold: equal to.

  • 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.

Note

You must configure at least one of the following alert levels: Critical, Warn, and Info. For the configured alert level, you must configure the Statistics, ComparisonOperator, Threshold, and Times parameters at the same time.

GreaterThanOrEqualToThreshold

Escalations.Critical.Threshold

string

No

The Critical-level alert threshold.

Note

You must configure at least one of the following alert levels: Critical, Warn, and Info. For the configured alert level, you must configure the Statistics, ComparisonOperator, Threshold, and Times parameters at the same time.

90

Escalations.Critical.Times

integer

No

The number of retries for the Critical-level alert.

Note

You must configure at least one of the following alert levels: Critical, Warn, and Info. For the configured alert level, you must configure the Statistics, ComparisonOperator, Threshold, and Times parameters at the same time.

3

Escalations.Warn.Statistics

string

No

The statistical method for the Warn-level alert.

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

Note

You must configure at least one of the following alert levels: Critical, Warn, and Info. For the configured alert level, the Settings for the Statistics, ComparisonOperator, Threshold, and Times parameters must be specified at the same time.

Average

Escalations.Warn.ComparisonOperator

string

No

The comparison operator for the Warn-level threshold. Valid values:

  • GreaterThanOrEqualToThreshold: greater than or equal to.

  • GreaterThanThreshold: greater than.

  • LessThanOrEqualToThreshold: less than or equal to.

  • LessThanThreshold: less than.

  • NotEqualToThreshold: not equal to.

  • EqualToThreshold: equal to.

  • 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.

Note

You must configure at least one of the following alert levels: Critical, Warn, and Info. For the configured alert level, you must configure the Statistics, ComparisonOperator, Threshold, and Times parameters at the same time.

GreaterThanOrEqualToThreshold

Escalations.Warn.Threshold

string

No

The Warn-level alert threshold.

Note

You must configure at least one of the following alert levels: Critical, Warn, and Info. For the configured alert level, you must configure the Statistics, ComparisonOperator, Threshold, and Times parameters at the same time.

90

Escalations.Warn.Times

integer

No

The number of retries for the Warn-level alert.

Note

You must configure at least one of the following alert levels: Critical, Warn, and Info. For the configured alert level, you must configure the Statistics, ComparisonOperator, Threshold, and Times parameters at the same time.

3

Escalations.Info.Statistics

string

No

The statistical method for the Info-level alert.

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

Note

You must configure at least one of the following alert levels: Critical, Warn, and Info. For the configured alert level, the Settings for the Statistics, ComparisonOperator, Threshold, and Times parameters must be specified at the same time.

Average

Escalations.Info.ComparisonOperator

string

No

The comparison operator for the Info-level threshold. Valid values:

  • GreaterThanOrEqualToThreshold: greater than or equal to.

  • GreaterThanThreshold: greater than.

  • LessThanOrEqualToThreshold: less than or equal to.

  • LessThanThreshold: less than.

  • NotEqualToThreshold: not equal to.

  • EqualToThreshold: equal to.

  • 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.

Note

You must configure at least one of the following alert levels: Critical, Warn, and Info. For the configured alert level, you must configure the Statistics, ComparisonOperator, Threshold, and Times parameters at the same time.

GreaterThanOrEqualToThreshold

Escalations.Info.Threshold

string

No

The Info-level alert threshold.

Note

You must configure at least one of the following alert levels: Critical, Warn, and Info. For the configured alert level, you must configure the Statistics, ComparisonOperator, Threshold, and Times parameters at the same time.

90

Escalations.Info.Times

integer

No

The number of retries for the Info-level alert.

Note

You must configure at least one of the following alert levels: Critical, Warn, and Info. For the configured alert level, you must configure the Statistics, ComparisonOperator, Threshold, and Times parameters at the same time.

3

NoDataPolicy

string

No

The action to take when no monitoring data is available. Valid values:

  • KEEP_LAST_STATE: takes no action. This is the default value.

  • INSUFFICIENT_DATA: triggers an alert indicating that no data is available.

  • OK: triggers an alert indicating that the status is normal.

KEEP_LAST_STATE

CompositeExpression

object

No

The alert conditions for multiple metrics.

Note

Single-metric and multi-metric alert conditions are mutually exclusive and cannot be configured at the same time.

ExpressionList

array<object>

No

The list of alert conditions created by using the standard method.

object

No

None.

MetricName

string

No

The metric name of the Alibaba Cloud service.

cpu_total

Period

integer

No

The aggregation period of the metric.

Unit: seconds.

60

Statistics

string

No

The statistical method of the metric. Valid values:

  • $Maximum: the maximum value.

  • $Minimum: the minimum value.

  • $Average: the average value.

  • $Availability: the active rate. This value is typically used for site monitoring.

Note

$ is the unified prefix for metrics. For more information about supported Alibaba Cloud services, see Alibaba Cloud service monitoring metrics.

$Maximum

ComparisonOperator

string

No

The threshold comparison operator. Valid values:

  • GreaterThanOrEqualToThreshold: greater than or equal to.

  • GreaterThanThreshold: greater than.

  • LessThanOrEqualToThreshold: less than or equal to.

  • LessThanThreshold: less than.

  • NotEqualToThreshold: not equal to.

  • EqualToThreshold: equal to.

  • 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.

GreaterThanOrEqualToThreshold

Threshold

string

No

The alert threshold.

90

ExpressionListJoin

string

No

The relationship between the alert conditions for multiple metrics. Valid values:

  • &&: triggers an alert only when all metrics meet the alert conditions. An alert is triggered only when all expressions in ExpressionList evaluate to true.

  • ||: triggers an alert when any metric meets the alert condition.

||

ExpressionRaw

string

No

The alert conditions created by using expressions. This includes but is not limited to the following scenarios:

  • Set an alert blacklist for specific resources. Example: $instanceId != 'i-io8kfvcpp7x5****' && $Average > 50. This indicates that no alert is triggered even if the Average value of the instance i-io8kfvcpp7x5**** in the alert rule is greater than 50.

  • Set a special alert threshold for a specific instance in the rule. Example: $Average > ($instanceId == 'i-io8kfvcpp7x5****'? 80: 50). This indicates that an alert is triggered only when the Average value of the instance i-io8kfvcpp7x5**** in the alert rule is greater than 80. For other instances, an alert is triggered when the Average value is greater than 50.

  • Limit the number of instances that exceed the threshold in the rule. Example: count($Average > 20) > 3. This indicates that an alert is triggered only when the number of instances whose Average value is greater than 20 in the alert rule is greater than 3.

$Average > ($instanceId == 'i-io8kfvcpp7x5****'? 80: 50)

Level

string

No

The alert level. Valid values:

  • CRITICAL: critical.

  • WARN: warning.

  • INFO: info.

CRITICAL

Times

integer

No

The number of times the alert condition must be met before an alert notification is sent.

3

Labels

array<object>

No

The labels that are written to the metric and displayed in the alert notification when the metric meets the alert condition and an alert is triggered.

Note

This feature is the same as the Label feature in Prometheus alerts.

object

No

None.

Key

string

No

The label key.

tagKey1

Value

string

No

The label value.

Note

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

ECS

Prometheus

object

No

The Prometheus alert.

Note

You need to configure this parameter only when you create a Prometheus alert rule for Hybrid Cloud Monitoring.

PromQL

string

No

The PromQL query statement.

Note

The data obtained by using the PromQL query statement is used as the alert data. You must include the alert threshold in this statement.

cpuUsage{instanceId="xxxx"}[1m]>90

Level

string

No

The alert level. Valid values:

  • CRITICAL: critical.

  • WARN: warning.

  • INFO: info.

CRITICAL

Times

integer

No

The number of times the alert condition must be met before an alert notification is sent.

3

Annotations

array<object>

No

The annotations whose keys and values are rendered during Prometheus alerts to help you understand the metrics or alert rules.

Note

This feature is equivalent to the Annotation feature in Prometheus.

object

No

None.

Key

string

No

The annotation key.

summary

Value

string

No

The annotation value.

{{ $labels.instance }} CPU usage above 10% {current value: {{ humanizePercentage $value }} }

SendOK

boolean

No

Specifies whether to send a recovery notification.

true

DryRun

boolean

No

Specifies whether to only precheck the request. Valid values:

  • true: sends a check request and does not bind a security group to the instance. The system checks whether the required parameters are specified, the request format is valid, and the service limits are met. If the request fails the check, the system returns an error. If the request passes the check, the system returns the error code DryRunOperation.

  • false: sends a normal request. If the request passes the check, the system returns an HTTP 2xx status code and performs the operation. This is the default value.

false

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

200 indicates success.

200

Message

string

The error message.

The request processing has failed due to some unknown error.

RequestId

string

The request ID.

65D50468-ECEF-48F1-A6E1-D952E89D9436

Success

boolean

Indicates whether the operation was successful. Valid values:

  • true: successful.

  • false: failed.

true

Examples

Success response

JSON format

{
  "Code": "200",
  "Message": "The request processing has failed due to some unknown error.",
  "RequestId": "65D50468-ECEF-48F1-A6E1-D952E89D9436",
  "Success": true
}

Error codes

HTTP status code

Error code

Error message

Description

400 %s %s
499 %s %s
412 DryRunOperation %s. dryRun Pre-Verification Results
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
429 ResourceOverLimit The resource has exceeded the limit. %s The quantity limit has been exceeded.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.