ALIYUN::CMS::ResourceMetricRule

更新时间:
复制 MD 格式

ALIYUN::CMS::ResourceMetricRule is used to create a threshold-triggered alert rule for a metric of a resource.

Syntax

{
  "Type": "ALIYUN::CMS::ResourceMetricRule",
  "Properties": {
    "NoEffectiveInterval": String,
    "ContactGroups": List,
    "SilenceTime": Integer,
    "RuleId": String,
    "Period": Integer,
    "Prometheus": Map,
    "Labels": List,
    "EffectiveInterval": String,
    "NoDataPolicy": String,
    "Namespace": String,
    "MetricName": String,
    "DeletionForce": Boolean,
    "Escalations": Map,
    "EmailSubject": String,
    "CompositeExpression": Map,
    "Webhook": String,
    "Resources": List,
    "RuleName": String,
    "Interval": Integer
  }
}

Properties

Property

Type

Required

Editable

Description

Constraint

ContactGroups

List

Yes

Yes

The alert contact groups.

CloudMonitor sends alert notifications to the alert contacts that belong to the alert contact groups.

Note

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

Escalations

Map

No

Yes

Details of the alerts.

For more information, see Escalations properties.

MetricName

String

Yes

Yes

The metric name.

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

Note

If you create a Prometheus alert rule for Hybrid Cloud Monitoring, you must set this property to a namespace name. For more information about how to query a namespace name, see DescribeHybridMonitorNamespaceList.

Namespace

String

Yes

Yes

The namespace of the cloud service.

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

Note

You must set this property to acs_prometheus when you create a Prometheus alert rule for Hybrid Cloud Monitoring.

Resources

List

Yes

Yes

The information about the resources.

Examples: [{"instanceId":"i-uf6j91r34rnwawoo****"}] and [{"userId":"100931896542****"}]. See Metrics for cloud services for the supported resource dimensions.

CompositeExpression

Map

No

Yes

The trigger conditions for multiple metrics.

For more information, see CompositeExpression properties.

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 in a request.

DeletionForce

Boolean

No

Yes

Specifies whether to forcefully delete the alert rule.

Valid values:

  • true

  • false

EffectiveInterval

String

No

Yes

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

Example: 00:00-23:59.

EmailSubject

String

No

Yes

The subject of the alert notification email.

None.

Interval

Integer

No

Yes

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

Unit: seconds.

Note

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

Labels

List

No

Yes

The information about the tags.

For more information, see Labels properties.

NoDataPolicy

String

No

Yes

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

Valid values:

  • KEEP_LAST_STATE (default): performs no operation.

  • INSUFFICIENT_DATA: triggers an alert whose content is "Insufficient data".

  • OK: considers the status normal.

NoEffectiveInterval

String

No

Yes

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

Example: 00:00-23:59.

Period

Integer

No

Yes

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 period of a metric, see Appendix 1: Metrics.

Prometheus

Map

No

Yes

The information about the Prometheus alert rule.

For more information, see Prometheus properties.

Note

You must specify this property when you create a Prometheus alert rule for Hybrid Cloud Monitoring.

RuleId

String

No

No

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 ID of an alert rule, see DescribeMetricRuleList.

Note

If you specify a new ID, a threshold-triggered alert rule is created.

RuleName

String

No

Yes

The name of the alert rule.

You can specify a new name or the name of an existing alert rule in CloudMonitor. For more 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.

SilenceTime

Integer

No

Yes

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.

Webhook

String

No

Yes

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

None.

Prometheus syntax

"Prometheus": {
  "Annotations": List,
  "PromQL": String,
  "Times": Integer,
  "Level": String
}

Prometheus properties

Property

Type

Required

Editable

Description

Constraint

Level

String

Yes

Yes

The alert level.

Valid values:

  • Critical

  • Warn

  • Info

PromQL

String

Yes

Yes

The PromQL query statement.

None.

Times

Integer

Yes

Yes

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

None.

Annotations

List

No

Yes

The annotations of the Prometheus alert rule. When a Prometheus alert is triggered, the system renders the keys and values of the annotations.

For more information, see Annotations properties.

Note

This property has the same effect as the Annotation property in the Prometheus property.

Annotations syntax

"Annotations": [
  {
    "Value": String,
    "Key": String
  }
]

Annotations properties

Property

Type

Required

Editable

Description

Constraint

Key

String

No

Yes

The key of the annotation.

None.

Value

String

No

Yes

The value of the annotation.

None.

Labels syntax

"Labels": [
  {
    "Value": String,
    "Key": String
  }
]

Labels properties

Property

Type

Required

Editable

Description

Constraint

Key

String

Yes

Yes

The tag key.

None.

Value

String

No

Yes

The tag value.

None.

Escalations syntax

"Escalations": {
  "Critical": Map,
  "Info": Map,
  "Warn": Map
}

Escalations properties

Property

Type

Required

Editable

Description

Constraint

Critical

Map

No

Yes

Details of the Critical-level alerts.

For more information, see Critical properties.

Info

Map

No

Yes

Details of the Info-level alerts.

For more information, see Info properties.

Warn

Map

No

Yes

Details of the Warn-level alerts.

For more information, see Warn properties.

Critical syntax

"Critical": {
  "ComparisonOperator": String,
  "Times": Integer,
  "Statistics": String,
  "Threshold": String
}

Critical properties

Property

Type

Required

Editable

Description

Constraint

ComparisonOperator

String

Yes

Yes

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

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 previous monitoring cycle

  • LessThanLastPeriod: less than the metric value in the previous monitoring cycle

Note

You must configure at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times properties for the alert level.

Statistics

String

Yes

Yes

The statistical method for the Critical-level alert.

Valid values:

  • Maximum: maximum value

  • Minimum: minimum value

  • Average: average value

  • Availability: availability rate

Note

You must configure at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times properties for the alert level.

Threshold

String

Yes

Yes

The threshold for the Critical-level alert.

Note

You must configure at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times properties for the alert level.

Times

Integer

Yes

Yes

The number of consecutive times for which the metric value must meet the trigger condition before the Critical-level alert is triggered.

Note

You must configure at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times properties for the alert level.

Info syntax

"Info": {
  "ComparisonOperator": String,
  "Times": Integer,
  "Statistics": String,
  "Threshold": String
}

Info properties

Property

Type

Required

Editable

Description

Constraint

ComparisonOperator

String

Yes

Yes

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

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 previous monitoring cycle

  • LessThanLastPeriod: less than the metric value in the previous monitoring cycle

Note

You must configure at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times properties for the alert level.

Statistics

String

Yes

Yes

The statistical method for the Info-level alert.

Valid values:

  • Maximum: maximum value

  • Minimum: minimum value

  • Average: average value

  • Availability: availability rate

Note

You must configure at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times properties for the alert level.

Threshold

String

Yes

Yes

The threshold for the Info-level alert.

Note

You must configure at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times properties for the alert level.

Times

Integer

Yes

Yes

The number of consecutive times for which the metric value must meet the trigger condition before the Info-level alert is triggered.

Note

You must configure at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times properties for the alert level.

Warn syntax

"Warn": {
  "ComparisonOperator": String,
  "Times": Integer,
  "Statistics": String,
  "Threshold": String
}

Warn properties

Property

Type

Required

Editable

Description

Constraint

ComparisonOperator

String

Yes

Yes

The operator that is used to compare the metric value with the threshold for the Warn-level alert.

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 previous monitoring cycle

  • LessThanLastPeriod: less than the metric value in the previous monitoring cycle

Note

You must configure at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times properties for the alert level.

Statistics

String

Yes

Yes

The statistical method for the Warn-level alert.

Valid values:

  • Maximum: maximum value

  • Minimum: minimum value

  • Average: average value

  • Availability: availability rate

Note

You must configure at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times properties for the alert level.

Threshold

String

Yes

Yes

The threshold for the Warn-level alert.

Note

You must configure at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times properties for the alert level.

Times

Integer

Yes

Yes

The number of consecutive times for which the metric value must meet the trigger condition before the Warn-level alert is triggered.

Note

You must configure at least one of the Critical, Warn, and Info alert levels and specify the Statistics, ComparisonOperator, Threshold, and Times properties for the alert level.

CompositeExpression syntax

"CompositeExpression": {
  "Times": Integer,
  "ExpressionRaw": String,
  "ExpressionListJoin": String,
  "Level": String,
  "ExpressionList": List
}

CompositeExpression properties

Property

Type

Required

Editable

Description

Constraint

Level

String

Yes

Yes

The alert level.

Valid values:

  • Critical

  • Warn

  • Info

Times

Integer

Yes

Yes

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

None.

ExpressionList

List

No

Yes

The trigger conditions created in standard mode.

For more information, see ExpressionList properties.

ExpressionListJoin

String

No

Yes

The relationship between the trigger conditions for multiple metrics.

Valid values:

  • &&: An alert is triggered only if all metrics meet the trigger conditions.

  • ||: An alert is triggered if one of the metrics meets the trigger conditions.

ExpressionRaw

String

No

Yes

The trigger conditions created by using expressions.

You can use expressions to create trigger conditions in the following scenarios:

  • You can set an alert blacklist for specific resources. For example, the expression $instanceId != 'i-io8kfvcpp7x5****' && $Average > 50 means that if the Average value for instance i-io8kfvcpp7x5**** is greater than 50, an alert is not triggered.

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

  • Limit the number of instances that exceed the threshold in the rule. For example, count($Average > 20) > 3 indicates that an alert is triggered only when the number of instances with an Average value greater than 20 exceeds 3.

ExpressionList syntax

"ExpressionList": [
  {
    "MetricName": String,
    "ComparisonOperator": String,
    "Period": Integer,
    "Id": String,
    "ExpressionRaw": String,
    "Statistics": String,
    "Threshold": String
  }
]

ExpressionList properties

Property

Type

Required

Editable

Description

Constraint

ComparisonOperator

String

Yes

Yes

The 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 previous monitoring cycle

  • LessThanLastPeriod: less than the metric value in the previous monitoring cycle

MetricName

String

Yes

Yes

The metric name of the cloud service.

None.

Period

Integer

Yes

Yes

The aggregation period of the metric.

Unit: seconds.

Statistics

String

Yes

Yes

The statistical method of the metric.

Valid values:

  • $Maximum: maximum value.

  • $Minimum: minimum value.

  • $Average: average value.

  • $Availability: availability rate. In most cases, the availability rate is used for site monitoring.

Note

$ is the prefix of the metric. For more information about the cloud services that are supported by CloudMonitor, see Appendix 1: Metrics.

Threshold

String

Yes

Yes

The alert threshold.

None.

Id

String

No

No

The ID of the alert condition.

None.

ExpressionRaw

String

No

No

A custom expression that defines the alert condition.

Use for advanced scenarios, such as:

  • You can set an alert exclusion list for specific resources. For example, the expression $instanceId != 'i-io8kfvcpp7x5****' ``&&`` $Average > 50 means that an alert is not triggered for instance i-io8kfvcpp7x5**** in the alert rule, even if its Average value is greater than 50.

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

  • Limit the number of instances in the rule that exceed the threshold. For example, count($Average > 20) > 3 means that an alert is triggered only when more than three instances have an Average value greater than 20.

Return values

Fn::GetAtt

  • RuleId: the ID of the alert rule.

  • RuleName: the name of the alert rule.

Examples


ROSTemplateFormatVersion: '2015-09-01'
Parameters:
 ContactGroups:
 Type: Json
 Description: |-
 The alert contact group that receives alert notifications.
 Note: An alert contact group can contain one or more alert contacts. To create alert contacts and alert contact groups, see PutContact and PutContactGroup.
 MinLength: 1
 Namespace:
 Type: String
 Description: |-
 The namespace of the cloud service.
 To find the namespace for a cloud service, see Appendix 1: Metrics.
 Note: If you create a Prometheus alert rule for Hybrid Cloud Monitoring, you must set this parameter to acs_prometheus.
 MetricName:
 Type: String
 Description: |-
 The name of the metric.
 To find the name of a metric, see Appendix 1: Metrics.
 Note: For Prometheus alert rules in Hybrid Cloud Monitoring, this parameter must be set to the name of the target namespace. To find a list of namespace names, call the DescribeHybridMonitorNamespaceList operation.
 Escalations:
 Type: Json
 Description: You must specify at least one alert level: Critical, Warn, or Info.
 MinLength: 1
 Resources:
 Type: Json
 Description: |-
 The resource to which the alert rule applies.
 Examples: [{"instanceId":"i-uf6j91r34rnwawoo****"}] and [{"userId":"100931896542****"}].
 For supported dimensions for querying resources, see Appendix 1: Metrics.
 MinLength: 1
Resources:
 ResourceMetricRule:
 Type: ALIYUN::CMS::ResourceMetricRule
 Properties:
 ContactGroups:
 Ref: ContactGroups
 Namespace:
 Ref: Namespace
 MetricName:
 Ref: MetricName
 Resources:
 Ref: Resources
 Escalations:
 Ref: Escalations
Outputs:
 RuleId:
 Description: The ID of the alert rule.
 Value:
 Fn::GetAtt:
 - ResourceMetricRule
 - RuleId
 RuleName:
 Description: The name of the alert rule.
 Value:
 Fn::GetAtt:
 - ResourceMetricRule
 - RuleName
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "ContactGroups": {
      "Type": "Json",
      "Description": "The alert contact group that receives alert notifications.\nNote: An alert contact group can contain one or more alert contacts. To create alert contacts and alert contact groups, see PutContact and PutContactGroup.",
      "MinLength": 1
    },
    "Namespace": {
      "Type": "String",
      "Description": "The namespace of the cloud service.\nTo find the namespace for a cloud service, see Appendix 1: Metrics.\nNote: If you create a Prometheus alert rule for Hybrid Cloud Monitoring, you must set this parameter to acs_prometheus."
    },
    "MetricName": {
      "Type": "String",
      "Description": "The name of the metric.\nTo find the name of a metric, see Appendix 1: Metrics.\nNote: For Prometheus alert rules in Hybrid Cloud Monitoring, this parameter must be set to the name of the target namespace. To find a list of namespace names, call the DescribeHybridMonitorNamespaceList operation."
    },
    "Escalations": {
      "Type": "Json",
      "Description": "You must specify at least one alert level: Critical, Warn, or Info.",
      "MinLength": 1
    },
    "Resources": {
      "Type": "Json",
      "Description": "The resource to which the alert rule applies.\nExamples: [{\"instanceId\":\"i-uf6j91r34rnwawoo****\"}] and [{\"userId\":\"100931896542****\"}].\nFor supported dimensions for querying resources, see Appendix 1: Metrics.",
      "MinLength": 1
    }
  },
  "Resources": {
    "ResourceMetricRule": {
      "Type": "ALIYUN::CMS::ResourceMetricRule",
      "Properties": {
        "ContactGroups": {
          "Ref": "ContactGroups"
        },
        "Namespace": {
          "Ref": "Namespace"
        },
        "MetricName": {
          "Ref": "MetricName"
        },
        "Resources": {
          "Ref": "Resources"
        },
        "Escalations": {
          "Ref": "Escalations"
        }
      }
    }
  },
  "Outputs": {
    "RuleId": {
      "Description": "The ID of the alert rule.",
      "Value": {
        "Fn::GetAtt": [
          "ResourceMetricRule",
          "RuleId"
        ]
      }
    },
    "RuleName": {
      "Description": "The name of the alert rule.",
      "Value": {
        "Fn::GetAtt": [
          "ResourceMetricRule",
          "RuleName"
        ]
      }
    }
  }
}