All Products
Search
Document Center

CloudMonitor:PutResourceMetricRules

Last Updated:Nov 01, 2024

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

Operation description

This topic provides an example on 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 metrics 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.

Note Statistics verification was added on August 15, 2024. Only the statistical value of the corresponding metric can be set for the Statistics parameter. For more information about how to obtain the value of this parameter, see Appendix 1: Metrics.

Debugging

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
cms:PutResourceMetricRulescreate
  • All Resources
    *
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
Rulesarray<object>Yes

The threshold-triggered alert rules.

Valid values of N: 1 to 500.

objectYes

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.
Escalations.Info.ThresholdstringNo

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 each alert level.
90
MetricNamestringNo

The metric name.

Valid values of N: 1 to 500.

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

cpu_total
Escalations.Warn.ThresholdstringNo

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 each alert level.
90
EffectiveIntervalstringNo

The time period during which the alert rule is effective.

Valid values of N: 1 to 500.

00:00-23:59
NoEffectiveIntervalstringNo

The time period during which the alert rule is ineffective.

Valid values of N: 1 to 500.

00:00-06:00
RuleIdstringYes

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.
a151cd6023eacee2f0978e03863cc1697c89508****
Escalations.Critical.TimesintegerNo

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 each alert level.
3
Escalations.Critical.ThresholdstringNo

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 each alert level.
90
Escalations.Critical.StatisticsstringNo

The statistical methods for Critical-level alerts.

Valid values of N: 1 to 500.

The value of this parameter is determined by the Statistics column corresponding to the MetricName parameter of the specified cloud service. The value of this parameter can be Maximum, Minimum, or Average. For more information about how to obtain the value of this parameter, see Appendix 1: Metrics.

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 each alert level.
Average
Escalations.Warn.ComparisonOperatorstringNo

The operator that is used to compare the metric value with the threshold 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 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 select at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times parameters for each alert level.
GreaterThanOrEqualToThreshold
Escalations.Info.TimesintegerNo

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 each alert level.
3
ResourcesstringYes

The information about the resource. Example: [{"instanceId":"i-uf6j91r34rnwawoo****"}] or [{"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.

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

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.
86400
WebhookstringNo

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.

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

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 .
ECS_Group
NamespacestringYes

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.

acs_ecs_dashboard
EmailSubjectstringNo

The subject of the alert notification email.

Valid values of N: 1 to 500.

PeriodstringNo

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.
60
RuleNamestringYes

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.
test123
Escalations.Info.StatisticsstringNo

The statistical methods for Info-level alerts.

Valid values of N: 1 to 500.

The value of this parameter is determined by the Statistics column corresponding to the MetricName parameter of the specified cloud service. The value of this parameter can be Maximum, Minimum, or Average. For more information about how to obtain the value of this parameter, see Appendix 1: Metrics.

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 each alert level.
Average
Escalations.Warn.TimesintegerNo

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 each alert level.
3
Escalations.Info.ComparisonOperatorstringNo

The operator that is used to compare the metric value with the threshold 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 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 select at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times parameters for each alert level.
GreaterThanOrEqualToThreshold
IntervalstringNo

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.
60
Escalations.Critical.ComparisonOperatorstringNo

The operator that is used to compare the metric value with the threshold 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 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 select at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times parameters for each alert level.
GreaterThanOrEqualToThreshold
Escalations.Warn.StatisticsstringNo

The statistical methods for Warn-level alerts.

Valid values of N: 1 to 500.

The value of this parameter is determined by the Statistics column corresponding to the MetricName parameter of the specified cloud service. The value of this parameter can be Maximum, Minimum, or Average. For more information about how to obtain the value of this parameter, see Appendix 1: Metrics.

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 each alert level.
Average
NoDataPolicystringNo

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

  • KEEP_LAST_STATE (default): 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.

KEEP_LAST_STATE
Labelsarray<object>No

If the metric meets the specified condition in the alert rule and CloudMonitor sends an alert notification, the tag is also written to the metric and displayed in the alert notification.

objectNo
KeystringNo

The tag key.

tagKey1
ValuestringNo

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

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

Response parameters

ParameterTypeDescriptionExample
object

None.

Codestring

The response code.

Note The status code 200 indicates that the request was successful.
200
Messagestring

The error message returned.

The request processing has failed due to some unknown error.
RequestIdstring

The request ID.

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

Indicates whether the request was successful. Valid values:

  • true
  • false
true
FailedListResultarray<object>

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

Targetobject
RuleIdstring

The ID of the alert rule.

a151cd6023eacee2f0978e03863cc1697c89508****
Resultobject

The alert rule that failed to be created.

Codestring

The response code.

404
Messagestring

The error message returned.

The request processing has failed due to some unknown error.
Successboolean

Indicates whether the request was successful. Valid values:

  • true
  • false
false

Examples

Sample success responses

JSONformat

{
  "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 codeError codeError message
204%s%s
500InternalErrorThe request processing has failed due to some unknown error.

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2021-10-28The Error code has changedView Change Details