全部產品
Search
文件中心

:ALIYUN::CMS::ResourceMetricRule

更新時間:Apr 11, 2026

ALIYUN::CMS::ResourceMetricRule類型用於為指定資源的指定監控項設定一條閾值警示規則。

文法

{
  "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
  }
}

屬性

屬性名稱

類型

必須

允許更新

描述

約束

ContactGroups

List

是

是

警示聯絡組。

警示通知會發送給該警示聯絡組中的警示連絡人。

說明

警示聯絡組包含警示連絡人,可以包含一個或多個警示連絡人。關於如何建立警示連絡人和警示聯絡組,請參見PutContact和PutContactGroup。

Escalations

Map

否

是

警示詳情。

更多資訊,請參見Escalations屬性。

MetricName

String

是

是

監控項名稱。

關於如何查詢監控項名稱,請參見雲產品監控項。

說明

當您為企業CloudMonitor建立Prometheus警示規則時,該參數為指標倉庫名稱。關於如何擷取指標倉庫名稱,請參見DescribeHybridMonitorNamespaceList。

Namespace

String

是

是

雲產品的資料命名空間。

關於如何查詢雲產品的資料命名空間,請參見雲產品監控項。

說明

當您為企業CloudMonitor建立Prometheus警示規則時,該參數必須為acs_prometheus。

Resources

List

是

是

資源資訊。

例如:[{"instanceId":"i-uf6j91r34rnwawoo****"}]、[{"userId":"100931896542****"}]。關於資源資訊支援的維度Dimensions,請參見雲產品監控項。

CompositeExpression

Map

否

是

多指標的警示條件。

更多資訊,請CompositeExpression屬性。

說明

單指標和多指標互斥,不能同時設定。

DeletionForce

Boolean

否

是

是否強制移除。

取值:

  • true:強制移除。

  • false:非強制移除。

EffectiveInterval

String

否

是

警示規則的生效時間範圍。

時間範圍:00:00-23:59。

EmailSubject

String

否

是

警示郵件主題。

無

Interval

Integer

否

是

警示規則的觸發周期。

單位:秒。

說明

關於如何查詢監控項的統計周期,請參見雲產品監控項。

Labels

List

否

是

標籤資訊。

更多資訊,請參見Labels屬性。

NoDataPolicy

String

否

是

無監控資料時警示的處理方式。

取值:

  • KEEP_LAST_STATE(預設值):不做任何處理。

  • INSUFFICIENT_DATA:警示內容為無資料。

  • OK:正常。

NoEffectiveInterval

String

否

是

警示規則的失效時間範圍。

時間範圍:00:00-23:59。

Period

Integer

否

是

監控項的統計周期。

單位:秒。預設值:監控項的原始上報周期。

說明

關於如何查詢監控項的統計周期,請參見附錄1 雲產品監控指標。

Prometheus

Map

否

是

Prometheus警示。

更多資訊,請參見Prometheus屬性。

說明

當您為企業CloudMonitor建立Prometheus警示規則時,該參數必須設定。

RuleId

String

否

否

警示規則ID。

您可以輸入新的警示規則ID或輸入已存在的警示規則ID。關於如何查詢警示規則ID,請參見DescribeMetricRuleList。

說明

輸入新的警示規則ID,表示建立一條新的閾值警示規則。

RuleName

String

否

是

警示規則名稱。

您可以輸入新的警示規則名稱或輸入CloudMonitor已存在的警示規則名稱。關於如何查詢警示規則名稱,請參見DescribeMetricRuleList。

說明

輸入新的警示規則名稱,表示建立一條新的閾值警示規則。

SilenceTime

Integer

否

是

通道沉默周期。

單位:秒。預設值:86400。

說明

通道沉默周期是指警示發生後未恢複正常,間隔多久重新發送一次警示通知。

Webhook

String

否

是

警示發生回調時指定的URL地址,向URL發送POST請求。

無

Prometheus文法

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

Prometheus屬性

屬性名稱

類型

必須

允許更新

描述

約束

Level

String

是

是

警示層級。

取值:

  • Critical:嚴重。

  • Warn:警告。

  • Info:資訊。

PromQL

String

是

是

PromQL查詢語句。

無

Times

Integer

是

是

發出警示通知需要達到警示條件的次數。

無

Annotations

List

否

是

Prometheus警示時,將注釋的鍵和值進行渲染。多指標警示條件之間的關係。

更多資訊,請參見Annotations屬性。

說明

該參數的效果與Prometheus參數取值為Annotation的效果相同。

Annotations文法

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

Annotations屬性

屬性名稱

類型

必須

允許更新

描述

約束

Key

String

否

是

注釋的鍵。

無

Value

String

否

是

注釋的值。

無

Labels文法

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

Labels屬性

屬性名稱

類型

必須

允許更新

描述

約束

Key

String

是

是

標籤鍵。

無

Value

String

否

是

標籤值。

無

Escalations文法

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

Escalations屬性

屬性名稱

類型

必須

允許更新

描述

約束

Critical

Map

否

是

嚴重層級警示詳情。

更多資訊,請參見Critical屬性。

Info

Map

否

是

資訊層級警示詳情。

更多資訊,請參見Info屬性。

Warn

Map

否

是

警告層級警示詳情。

更多資訊,請參見Warn屬性。

Critical文法

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

Critical屬性

屬性名稱

類型

必須

允許更新

描述

約束

ComparisonOperator

String

是

是

嚴重層級閾值比較符。

取值:

  • GreaterThanOrEqualToThreshold:大於等於。

  • GreaterThanThreshold:大於。

  • LessThanOrEqualToThreshold:小於等於。

  • LessThanThreshold:小於。

  • NotEqualToThreshold:不等於。

  • GreaterThanYesterday:同比昨天時間上漲。

  • LessThanYesterday:同比昨天時間下降。

  • GreaterThanLastWeek:同比上周同一時間上漲。

  • LessThanLastWeek:同比上周同一時間下降。

  • GreaterThanLastPeriod:環比上周期上漲。

  • LessThanLastPeriod:環比上周期下降。

說明

您需要設定警示層級Critical(嚴重)、Warn(警告)或Info(資訊)至少一個,且該警示層級中的參數Statistics、ComparisonOperator、Threshold和Times必須同時設定。

Statistics

String

是

是

嚴重層級警示統計方法。

取值:

  • Maximum:最大值。

  • Minimum:最小值。

  • Average:平均值。

  • Availability:可用率。

說明

您需要設定警示層級Critical(嚴重)、Warn(警告)或Info(資訊)至少一個,且該警示層級中的參數Statistics、ComparisonOperator、Threshold和Times必須同時設定。

Threshold

String

是

是

嚴重層級警示閾值。

說明

您需要設定警示層級Critical(嚴重)、Warn(警告)或Info(資訊)至少一個,且該警示層級中的參數Statistics、ComparisonOperator、Threshold和Times必須同時設定。

Times

Integer

是

是

嚴重層級警示重試次數。

說明

您需要設定警示層級Critical(嚴重)、Warn(警告)或Info(資訊)至少一個,且該警示層級中的參數Statistics、ComparisonOperator、Threshold和Times必須同時設定。

Info文法

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

Info屬性

屬性名稱

類型

必須

允許更新

描述

約束

ComparisonOperator

String

是

是

資訊層級閾值比較符。

取值:

  • GreaterThanOrEqualToThreshold:大於等於。

  • GreaterThanThreshold:大於。

  • LessThanOrEqualToThreshold:小於等於。

  • LessThanThreshold:小於。

  • NotEqualToThreshold:不等於。

  • GreaterThanYesterday:同比昨天時間上漲。

  • LessThanYesterday:同比昨天時間下降。

  • GreaterThanLastWeek:同比上周同一時間上漲。

  • LessThanLastWeek:同比上周同一時間下降。

  • GreaterThanLastPeriod:環比上周期上漲。

  • LessThanLastPeriod:環比上周期下降。

說明

您需要設定警示層級Critical(嚴重)、Warn(警告)或Info(資訊)至少一個,且該警示層級中的參數Statistics、ComparisonOperator、Threshold和Times必須同時設定。

Statistics

String

是

是

資訊層級警示統計方法。

取值:

  • Maximum:最大值。

  • Minimum:最小值。

  • Average:平均值。

  • Availability:可用率。

說明

您需要設定警示層級Critical(嚴重)、Warn(警告)或Info(資訊)至少一個,且該警示層級中的參數Statistics、ComparisonOperator、Threshold和Times必須同時設定。

Threshold

String

是

是

資訊層級警示閾值。

說明

您需要設定警示層級Critical(嚴重)、Warn(警告)或Info(資訊)至少一個,且該警示層級中的參數Statistics、ComparisonOperator、Threshold和Times必須同時設定。

Times

Integer

是

是

資訊層級警示重試次數。

說明

您需要設定警示層級Critical(嚴重)、Warn(警告)或Info(資訊)至少一個,且該警示層級中的參數Statistics、ComparisonOperator、Threshold和Times必須同時設定。

Warn文法

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

Warn屬性

屬性名稱

類型

必須

允許更新

描述

約束

ComparisonOperator

String

是

是

警告層級閾值比較符。

取值:

  • GreaterThanOrEqualToThreshold:大於等於。

  • GreaterThanThreshold:大於。

  • LessThanOrEqualToThreshold:小於等於。

  • LessThanThreshold:小於。

  • NotEqualToThreshold:不等於。

  • GreaterThanYesterday:同比昨天時間上漲。

  • LessThanYesterday:同比昨天時間下降。

  • GreaterThanLastWeek:同比上周同一時間上漲。

  • LessThanLastWeek:同比上周同一時間下降。

  • GreaterThanLastPeriod:環比上周期上漲。

  • LessThanLastPeriod:環比上周期下降。

說明

你需要設定警示層級Critical(嚴重)、Warn(警告)或Info(資訊)至少一個,且該警示層級中的參數Statistics、ComparisonOperator、Threshold和Times必須同時設定。

Statistics

String

是

是

警告層級警示統計方法。

取值:

  • Maximum:最大值。

  • Minimum:最小值。

  • Average:平均值。

  • Availability:可用率。

說明

您需要設定警示層級Critical(嚴重)、Warn(警告)或Info(資訊)至少一個,且該警示層級中的參數Statistics、ComparisonOperator、Threshold和Times必須同時設定。

Threshold

String

是

是

警告層級警示閾值。

說明

您需要設定警示層級Critical(嚴重)、Warn(警告)或Info(資訊)至少一個,且該警示層級中的參數Statistics、ComparisonOperator、Threshold和Times必須同時設定。

Times

Integer

是

是

警告層級警示重試次數。

說明

您需要設定警示層級Critical(嚴重)、Warn(警告)或Info(資訊)至少一個,且該警示層級中的參數Statistics、ComparisonOperator、Threshold和Times必須同時設定。

CompositeExpression文法

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

CompositeExpression屬性

屬性名稱

類型

必須

允許更新

描述

約束

Level

String

是

是

警示層級。

取值:

  • Critical:嚴重。

  • Warn:警告。

  • Info:資訊。

Times

Integer

是

是

發出警示通知需要達到警示條件的次數。

無

ExpressionList

List

否

是

標準建立的警示條件列表。

更多資訊,請參見ExpressionList屬性。

ExpressionListJoin

String

否

是

多指標警示條件之間的關係。

取值:

  • &&:當所有指標都符合警示條件時,才觸發警示。

  • ||:其中一個指標符合警示條件,即觸發警示。

ExpressionRaw

String

否

是

運算式建立的警示條件。

包括但不限於以下情況:

  • 為部分資源設定警示黑名單,例如:$instanceId != 'i-io8kfvcpp7x5****' && $Average > 50,表示當警示規則中的執行個體i-io8kfvcpp7x5****的Average大於50時,也不會產生警示。

  • 對規則中的指定執行個體設定特殊警示閾值,例如:$Average > ($instanceId == 'i-io8kfvcpp7x5****'? 80: 50),表示當警示規則中的執行個體i-io8kfvcpp7x5****的Average大於80時,才警示,其他執行個體的Average大於50,即可警示。

  • 對規則中超過閾值的執行個體數量進行限制,例如:count($Average > 20) > 3,表示當警示規則中的Average大於20的執行個體數大於3個時,才進行警示。

ExpressionList文法

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

ExpressionList屬性

屬性名稱

類型

必須

允許更新

描述

約束

ComparisonOperator

String

是

是

閾值比較符。

取值:

  • GreaterThanOrEqualToThreshold:大於等於。

  • GreaterThanThreshold:大於。

  • LessThanOrEqualToThreshold:小於等於。

  • LessThanThreshold:小於。

  • NotEqualToThreshold:不等於。

  • GreaterThanYesterday:同比昨天時間上漲。

  • LessThanYesterday:同比昨天時間下降。

  • GreaterThanLastWeek:同比上周同一時間上漲。

  • LessThanLastWeek:同比上周同一時間下降。

  • GreaterThanLastPeriod:環比上周期上漲。

  • LessThanLastPeriod:環比上周期下降。

MetricName

String

是

是

雲產品的監控項名稱。

無

Period

Integer

是

是

監控項的彙總周期。

單位:秒。

Statistics

String

是

是

監控項的統計方法。

取值:

  • $Maximum:最大值。

  • $Minimum:最小值。

  • $Average:平均值。

  • $Availability:可用率(通常用於網站監控)。

說明

$為監控項的統一首碼符號。關於CloudMonitor支援的雲產品,請參見雲產品監控項。

Threshold

String

是

是

警示閾值。

無

Id

String

否

否

條件ID

無

ExpressionRaw

String

否

否

運算式建立的警示條件。

包括但不限於以下情況:

  • 為部分資源設定警示黑名單,例如:$instanceId != 'i-io8kfvcpp7x5****' ``&&`` $Average > 50,表示當警示規則中的執行個體i-io8kfvcpp7x5****的Average大於 50 時,也不會產生警示。

  • 對規則中的指定執行個體設定特殊警示閾值,例如:$Average > ($instanceId == 'i-io8kfvcpp7x5****'? 80: 50),表示當警示規則中的執行個體i-io8kfvcpp7x5****的Average大於 80 時,才警示,其他執行個體的Average大於 50,即可警示。

  • 對規則中超過閾值的執行個體數量進行限制,例如:count($Average > 20) > 3,表示當警示規則中的Average大於 20 的執行個體數大於 3 個時,才進行警示。

傳回值

Fn::GetAtt

  • RuleId:警示規則ID。

  • RuleName:警示規則名稱。

樣本


ROSTemplateFormatVersion: '2015-09-01'
Parameters:
 ContactGroups:
 Type: Json
 Description: |-
 The alert contact group.
 The alert notifications are sent to the contacts that belong to 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.
 MinLength: 1
 Namespace:
 Type: String
 Description: |-
 The namespace of the cloud service.
 For information about how to query the namespace of a cloud service, 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.
 For information about how to query the name of a metric, 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 information about how to obtain the name of a namespace, see DescribeHybridMonitorNamespaceList.
 Escalations:
 Type: Json
 Description: You must select at least one of the Critical, Warn, and Info alert levels.
 MinLength: 1
 Resources:
 Type: Json
 Description: |-
 The information about the resource.
 Examples: [{"instanceId":"i-uf6j91r34rnwawoo****"}] and [{"userId":"100931896542****"}].
 For information about the supported dimensions that are used to query 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.\nThe alert notifications are sent to the contacts that belong to the alert contact group.\nNote: 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.",
      "MinLength": 1
    },
    "Namespace": {
      "Type": "String",
      "Description": "The namespace of the cloud service.\nFor information about how to query the namespace of a cloud service, 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.\nFor information about how to query the name of a metric, see Appendix 1: Metrics.\nNote: If you create a Prometheus alert rule for Hybrid Cloud Monitoring, you must set this parameter to the name of the namespace. For information about how to obtain the name of a namespace, see DescribeHybridMonitorNamespaceList."
    },
    "Escalations": {
      "Type": "Json",
      "Description": "You must select at least one of the Critical, Warn, and Info alert levels.",
      "MinLength": 1
    },
    "Resources": {
      "Type": "Json",
      "Description": "The information about the resource.\nExamples: [{\"instanceId\":\"i-uf6j91r34rnwawoo****\"}] and [{\"userId\":\"100931896542****\"}].\nFor information about the supported dimensions that are used to query 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"
        ]
      }
    }
  }
}