All Products
Search
Document Center

CloudMonitor:PutResourceMetricRule

Last Updated:May 21, 2024

Creates an alert rule for a metric of a 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.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer.

Authorization information

There is currently no authorization information disclosed in the API.

Request parameters

ParameterTypeRequiredDescriptionExample
RuleIdstringYes

The ID of the alert rule.

You can specify a new ID or the ID of an existing alert rule. For more information about how to query the IDs of alert rules, see DescribeMetricRuleList .

Note If you specify a new ID, a threshold-triggered alert rule is created.
a151cd6023eacee2f0978e03863cc1697c89508****
RuleNamestringYes

The name of the alert rule.

You can specify a new name or the name of an existing alert rule. For more information about how to query the names of alert rules, see DescribeMetricRuleList .

Note If you specify a new name, a threshold-triggered alert rule is created.
test123
NamespacestringYes

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

Note If you create a Prometheus alert rule for Hybrid Cloud Monitoring, you must set this parameter to acs_prometheus.
acs_ecs_dashboard
MetricNamestringYes

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

Note If you create a Prometheus alert rule for Hybrid Cloud Monitoring, you must set this parameter to the name of the namespace. For more information about how to query the names of namespaces, see DescribeHybridMonitorNamespaceList .
cpu_total
ResourcesstringYes

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

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

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

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

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
WebhookstringNo

The callback URL to which a POST request is sent when an alert is triggered based on the alert rule.

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

The period of time during which the alert rule is effective.

00:00-23:59
NoEffectiveIntervalstringNo

The period of time during which the alert rule is ineffective.

00:00-06:00
SilenceTimeintegerNo

The mute period during which new alert notifications are not sent even if the trigger conditions are met. Unit: seconds. Default value: 86400.

Note If an alert is not cleared after the mute period ends, CloudMonitor resends an alert notification.
86400
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.

Note For more information about how to query the statistical periods of metrics, see Appendix 1: Metrics.
60
IntervalstringNo

The interval at which alerts are triggered based on the alert rule. Unit: seconds.

Note For more information about how to query the statistical periods of metrics, see Appendix 1: Metrics.
60
EmailSubjectstringNo

The subject of the alert notification email.

Escalations.Critical.StatisticsstringNo

The statistical methods for Critical-level alerts.

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

The operator that is used to compare the metric value with the threshold for Critical-level alerts. Valid value:

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

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

The consecutive number of times for which the metric value meets the alert condition 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 each alert level.
3
Escalations.Warn.StatisticsstringNo

The statistical methods for Warn-level alerts.

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 value:

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

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

The consecutive number of times for which the metric value meets the alert condition 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 each alert level.
3
Escalations.Info.StatisticsstringNo

The statistical methods for Info-level alerts.

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.Info.ComparisonOperatorstringNo

The operator that is used to compare the metric value with the threshold for Info-level alerts. Valid value:

  • 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
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.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
Escalations.Info.TimesintegerNo

The consecutive number of times for which the metric value meets the alert condition 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 each alert level.
3
NoDataPolicystringNo

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

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

The trigger conditions for multiple metrics.

Note The trigger conditions for a single metric and multiple metrics are mutually exclusive. You cannot specify trigger conditions for a single metric and multiple metrics at the same time.
ExpressionListobject []No

The trigger conditions that are created in standard mode.

MetricNamestringNo

The metric that is used to monitor the cloud service.

cpu_total
PeriodlongNo

The aggregation period of the metric.

Unit: seconds.

60
StatisticsstringNo

The statistical method of the metric. Valid value:

  • $Maximum: the maximum value
  • $Minimum: the minimum value
  • $Average: the average value
  • $Availability: the availability rate (usually used for site monitoring)
Note $ is the prefix of the metric. For information about the Alibaba Cloud services that are supported by CloudMonitor, see Appendix 1: Metrics.
$Maximum
ComparisonOperatorstringNo

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

  • 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
GreaterThanOrEqualToThreshold
ThresholdstringNo

The alert threshold.

90
ExpressionListJoinstringNo

The relationship between the trigger conditions for multiple metrics. Valid value:

  • &&: An alert is triggered only if all metrics meet the trigger conditions. An alert is triggered only if the results of all expressions specified in the ExpressionList parameter are true.
  • ||: An alert is triggered if one of the metrics meets the trigger conditions.
||
ExpressionRawstringNo

The trigger conditions that are created by using expressions. You can use expressions to create trigger conditions in the following scenarios:

  • Set an alert blacklist for specific resources. For example, if you specify $instanceId != 'i-io8kfvcpp7x5****' ``&&`` $Average > 50, no alert is triggered when the average metric value of the i-io8kfvcpp7x5**** instance exceeds 50.
  • Set a special alert threshold for a specified instance in the rule. For example, if you specify $Average > ($instanceId == 'i-io8kfvcpp7x5****'? 80: 50), an alert is triggered when the average metric value of the i-io8kfvcpp7x5**** instance exceeds 80 or the average metric value of other instances exceeds 50.
  • Limit the number of instances whose metric values exceed the threshold. For example, if you specify count($Average > 20) > 3, an alert is triggered only when the average metric value of more than three instances exceeds 20.
$Average > ($instanceId == 'i-io8kfvcpp7x5****'? 80: 50)
LevelstringNo

The alert level. Valid values:

  • Critical
  • Warn
  • Info
Critical
TimesintegerNo

The number of consecutive triggers. If the number of times that the metric values meet the trigger conditions reaches the value of this parameter, CloudMonitor sends alert notifications.

3
Labelsobject []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.

Note This parameter is equivalent to the Label parameter of Prometheus alerts.
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
PrometheusobjectNo

Prometheus alerts.

Note This parameter is required only if you create a Prometheus alert rule for Hybrid Cloud Monitoring.
PromQLstringNo

PromQL statements are supported.

Note The data obtained by using the PromQL query statement is the monitoring data. You must include the alert threshold in this statement.
cpuUsage{instanceId="xxxx"}[1m]>90
LevelstringNo

The alert level. Valid values:

  • Critical
  • Warn
  • Info
Critical
TimesintegerNo

The number of consecutive triggers. If the number of times that the metric values meet the trigger conditions reaches the value of this parameter, CloudMonitor sends alert notifications.

3
Annotationsobject []No

The annotations of the Prometheus alert rule. When a Prometheus alert is triggered, the system renders the annotated keys and values to help you understand the metrics and alert rule.

Note This parameter is equivalent to the annotations parameter of open source Prometheus.
KeystringNo

The key of the annotation.

summary
ValuestringNo

The value of the annotation.

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

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

Response parameters

ParameterTypeDescriptionExample
object

None.

Codestring

The responses code.

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

The returned message.

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

The request ID.

65D50468-ECEF-48F1-A6E1-D952E89D9436
Successboolean

Indicates whether the request was successful. Valid values:

  • true
  • false
true

Examples

Sample success responses

JSONformat

{
  "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 codeError codeError message
204%s%s
429ResourceOverLimitThe resource has exceeded the limit. %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
2024-04-01The Error code has changedsee changesets
Change itemChange content
Error CodesThe Error code has changed.
    delete Error Codes: 204
    delete Error Codes: 206
    delete Error Codes: 400
    delete Error Codes: 403
    delete Error Codes: 404
    delete Error Codes: 406
    delete Error Codes: 429
    delete Error Codes: 499
    delete Error Codes: 500
    delete Error Codes: 503
2022-12-26The Error code has changedsee changesets
Change itemChange content
Error CodesThe Error code has changed.
    delete Error Codes: 204
    delete Error Codes: 206
    delete Error Codes: 400
    delete Error Codes: 403
    delete Error Codes: 404
    delete Error Codes: 406
    delete Error Codes: 429
    delete Error Codes: 499
    delete Error Codes: 500
    delete Error Codes: 503
2022-08-05The Error code has changedsee changesets
Change itemChange content
Error CodesThe Error code has changed.
    delete Error Codes: 204
    delete Error Codes: 206
    delete Error Codes: 400
    delete Error Codes: 403
    delete Error Codes: 404
    delete Error Codes: 406
    delete Error Codes: 499
    delete Error Codes: 500
    delete Error Codes: 503
    Added Error Codes: 429