CreateGroupMetricRules

更新时间:
复制 MD 格式

Creates alert rules in batches for a specified application group by calling the CreateGroupMetricRules operation.

Operation description

This topic provides an example on how to create an alert rule for the cpu_total metric of Elastic Compute Service (ECS) in the application group 123456. The alert rule ID is 456789, the alert rule name is ECS_Rule1, the alert severity is Critical, the statistical method is Average, the comparison operator is GreaterThanOrEqualToThreshold, the threshold is 90, and the retry count is 3. The response shows that the alert rule ECS_Rule1 is created.

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

create

*GroupMetricRule

acs:cms::{#accountId}:group/{#groupId}

None None

Request parameters

Parameter

Type

Required

Description

Example

GroupId

integer

Yes

The ID of the application group.

For information about how to obtain the application group ID, see DescribeMonitorGroups.

3607****

GroupMetricRules

array<object>

No

The list of metric-based alert rules for the application group.

array<object>

No

The metric-based alert rule for the application group.

Escalations.Info.Threshold

string

No

普通级别报警阈值。

N 的取值范围:1~200。

Note

报警级别 Critical(严重)、Warn(警告)或 Info(信息)至少设置一个,且该报警级别中的参数 Statistics、ComparisonOperator、Threshold 和 Times 必须同时设置。

10

MetricName

string

Yes

The name of the metric.

Valid values of N: 1 to 200.

For information about how to obtain the metric name, see DescribeMetricMetaList or Cloud service monitoring.

cpu_total

Escalations.Warn.Threshold

string

No

警告级别报警阈值。

N 的取值范围:1~200。

Note

报警级别 Critical(严重)、Warn(警告)或 Info(信息)至少设置一个,且该报警级别中的参数 Statistics、ComparisonOperator、Threshold 和 Times 必须同时设置。

20

EffectiveInterval

string

No

The effective period of the alert rule. Valid values of N: 1 to 200.

05:31-23:59

NoEffectiveInterval

string

No

The time period during which the alert rule is ineffective. Valid values of N: 1 to 200.

00:00-05:30

RuleId

string

Yes

The ID of the alert rule.

Valid values of N: 1 to 200.

456789

Escalations.Critical.Times

integer

No

发送紧急报警通知需要监控指标达到报警阈值的次数。

N 的取值范围:1~200。

Note

报警级别 Critical(严重)、Warn(警告)或 Info(信息)至少设置一个,且该报警级别中的参数 Statistics、ComparisonOperator、Threshold 和 Times 必须同时设置。

3

Dimensions

string

No

The monitoring dimensions of the specified resource.

The value is a collection of key:value pairs, such as {"userId":"120886317861****"} and {"instanceId":"i-2ze2d6j5uhg20x47****"}.

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

Escalations.Critical.Threshold

string

No

触发紧急级别报警通知的阈值。

N 的取值范围:1~200。

Note

报警级别 Critical(严重)、Warn(警告)或 Info(信息)至少设置一个,且该报警级别中的参数 Statistics、ComparisonOperator、Threshold 和 Times 必须同时设置。

90

Escalations.Critical.Statistics

string

No

紧急级别报警统计方法。

N 的取值范围:1~200。

该参数的取值由指定云产品的MetricName对应的Statistics列决定,例如:Maximum、Minimum 和 Average。关于如何获取该参数的取值,请参见云产品监控项

Note

报警级别 Critical(严重)、Warn(警告)或 Info(信息)至少设置一个,且该报警级别中的参数 Statistics、ComparisonOperator、Threshold 和 Times 必须同时设置。

Average

Escalations.Warn.ComparisonOperator

string

No

警告级别阈值比较符。取值:

  • GreaterThanOrEqualToThreshold:大于等于。

  • GreaterThanThreshold:大于。

  • LessThanOrEqualToThreshold:小于等于。

  • LessThanThreshold:小于。

  • NotEqualToThreshold:不等于。

  • GreaterThanYesterday:同比昨天时间上涨。

  • LessThanYesterday:同比昨天时间下降。

  • GreaterThanLastWeek:同比上周同一时间上涨。

  • LessThanLastWeek:同比上周同一时间下降。

  • GreaterThanLastPeriod:环比上周期上涨。

  • LessThanLastPeriod:环比上周期下降。

N 的取值范围:1~200。

Note

报警级别 Critical(严重)、Warn(警告)或 Info(信息)至少设置一个,且该报警级别中的参数 Statistics、ComparisonOperator、Threshold 和 Times 必须同时设置。

GreaterThanOrEqualToThreshold

Escalations.Info.Times

integer

No

发送普通报警通知需要监控指标达到报警阈值的次数。

N 的取值范围:1~200。

Note

报警级别 Critical(严重)、Warn(警告)或 Info(信息)至少设置一个,且该报警级别中的参数 Statistics、ComparisonOperator、Threshold 和 Times 必须同时设置。

1

SilenceTime

integer

No

The mute period of the alert notification. Valid values of N: 1 to 200.

Unit: seconds. Default value: 86400. Minimum value: 3600.

86400

Webhook

string

No

The callback URL to which an alert notification is sent. Valid values of N: 1 to 200.

Enter a publicly accessible URL. CloudMonitor sends alert information to this URL by using POST requests. Only the HTTP protocol is supported.

https://www.aliyun.com

Namespace

string

Yes

The namespace of the Alibaba Cloud service.

Valid values of N: 1 to 200.

For information about how to obtain the namespace of an Alibaba Cloud service, see DescribeMetricMetaList or Cloud service monitoring.

acs_ecs_dashboard

EmailSubject

string

No

The subject of the alert notification email.

Valid values of N: 1 to 200.

ECS instance

Period

string

No

The reporting period of monitoring data.

Valid values of N: 1 to 200.

The value of Period must be 60 or a multiple of 60. Unit: seconds. Default value: 300.

60

RuleName

string

Yes

The name of the alert rule.

Valid values of N: 1 to 200.

ECS_Rule1

Escalations.Info.Statistics

string

No

普通级别报警统计方法。

N 的取值范围:1~200。

该参数的取值由指定云产品的MetricName对应的Statistics列决定,例如:Maximum、Minimum 和 Average。关于如何获取该参数的取值,请参见云产品监控项

Note

报警级别 Critical(严重)、Warn(警告)或 Info(信息)至少设置一个,且该报警级别中的参数 Statistics、ComparisonOperator、Threshold 和 Times 必须同时设置。

Average

Escalations.Warn.Times

integer

No

发送警告报警通知需要监控指标达到报警阈值的次数。

N 的取值范围:1~200。

Note

报警级别 Critical(严重)、Warn(警告)或 Info(信息)至少设置一个,且该报警级别中的参数 Statistics、ComparisonOperator、Threshold 和 Times 必须同时设置。

3

Escalations.Info.ComparisonOperator

string

No

普通级别阈值比较符。取值:

  • GreaterThanOrEqualToThreshold:大于等于。

  • GreaterThanThreshold:大于。

  • LessThanOrEqualToThreshold:小于等于。

  • LessThanThreshold:小于。

  • NotEqualToThreshold:不等于。

  • GreaterThanYesterday:同比昨天时间上涨。

  • LessThanYesterday:同比昨天时间下降。

  • GreaterThanLastWeek:同比上周同一时间上涨。

  • LessThanLastWeek:同比上周同一时间下降。

  • GreaterThanLastPeriod:环比上周期上涨。

  • LessThanLastPeriod:环比上周期下降。

N 的取值范围:1~200。

Note

报警级别 Critical(严重)、Warn(警告)或 Info(信息)至少设置一个,且该报警级别中的参数 Statistics、ComparisonOperator、Threshold 和 Times 必须同时设置。

GreaterThanOrEqualToThreshold

Interval

string

No

The detection period of the alert rule.

Valid values of N: 1 to 200.

Unit: seconds. The default value is the minimum reporting period of the metric.

Note

Keep the detection period of the alert rule consistent with the data reporting period. If the detection period is shorter than the data reporting period, alerts may not be triggered due to insufficient data.

60

Category

string

Yes

The abbreviation of the Alibaba Cloud service name.

Valid values of N: 1 to 200.

For information about how to obtain the abbreviation, see the metricCategory tag in the Labels response parameter of the DescribeProjectMeta operation.

ECS

Escalations.Critical.ComparisonOperator

string

No

紧急级别阈值比较符。取值:

  • GreaterThanOrEqualToThreshold:大于等于。

  • GreaterThanThreshold:大于。

  • LessThanOrEqualToThreshold:小于等于。

  • LessThanThreshold:小于。

  • NotEqualToThreshold:不等于。

  • GreaterThanYesterday:同比昨天时间上涨。

  • LessThanYesterday:同比昨天时间下降。

  • GreaterThanLastWeek:同比上周同一时间上涨。

  • LessThanLastWeek:同比上周同一时间下降。

  • GreaterThanLastPeriod:环比上周期上涨。

  • LessThanLastPeriod:环比上周期下降。

N 的取值范围:1~200。

Note

报警级别 Critical(严重)、Warn(警告)或 Info(信息)至少设置一个,且该报警级别中的参数 Statistics、ComparisonOperator、Threshold 和 Times 必须同时设置。

GreaterThanOrEqualToThreshold

Escalations.Warn.Statistics

string

No

警告级别报警统计方法。

N 的取值范围:1~200。

该参数的取值由指定云产品的MetricName对应的Statistics列决定,例如:Maximum、Minimum 和 Average。关于如何获取该参数的取值,请参见云产品监控项

Note

报警级别 Critical(严重)、Warn(警告)或 Info(信息)至少设置一个,且该报警级别中的参数 Statistics、ComparisonOperator、Threshold 和 Times 必须同时设置。

Average

NoDataPolicy

string

No

The processing method when no monitoring data is found. Valid values:

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

KEEP_LAST_STATE

ContactGroups

string

No

The alert contact group.

Valid values of N: 1 to 200.

For information about how to obtain the alert contact group, see DescribeContactGroupList.

ECS_Group

Labels

array<object>

No

The tag keys of the alert rule.

object

No

The tag keys of the alert rule.

Key

string

No

The tag key of the alert rule. The tag is included in alert notifications.

Valid values of N: 1 to 200.

key1

Value

string

No

The tag value of the alert rule. The tag is included in alert notifications.

Valid values of N: 1 to 200.

value1

Options

string

No

The advanced settings.

Format: {"key1":"value1","key2":"value2"}. For example, {"NotSendOK":true} specifies whether to send an alert recovery notification. The key is NotSendOK, and the value is true (do not send) or false (send, which is the default).

{ "NotSendOK": true }

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

Response elements

Element

Type

Description

Example

object

Code

integer

The status code.

Note

A value of 200 indicates success.

200

Message

string

The error message.

The Request is not authorization.

RequestId

string

The request ID.

461CF2CD-2FC3-4B26-8645-7BD27E7D0F1D

Success

boolean

Indicates whether the operation was successful. Valid values:

  • true: Successful.

  • false: Failed.

true

Resources

object

AlertResult

array<object>

The list of alert rules.

object

Code

integer

The status code for creating the alert rule.

Note

A status code of 200 indicates that the operation was successful.

200

Message

string

The error message for creating the alert rule.

Metric not found.

Success

boolean

Indicates whether the alert rule was created. Valid values:

  • true: The alert rule was created.

  • false: The alert rule failed to be created.

true

RuleName

string

The name of the new alert rule.

ECS_Rule1

RuleId

string

The ID of the new alert rule.

456789

Examples

Success response

JSON format

{
  "Code": 200,
  "Message": "The Request is not authorization.",
  "RequestId": "461CF2CD-2FC3-4B26-8645-7BD27E7D0F1D",
  "Success": true,
  "Resources": {
    "AlertResult": [
      {
        "Code": 200,
        "Message": "Metric not found.",
        "Success": true,
        "RuleName": "ECS_Rule1",
        "RuleId": "456789"
      }
    ]
  }
}

Error codes

HTTP status code

Error code

Error message

Description

400 %s %s
412 %s %s
500 %s %s
500 500 %s
403 %s %s
404 %s %s
409 %s %s

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.