All Products
Search
Document Center

Auto Scaling:CreateAlarm

更新时间:Nov 29, 2025

You can call the CreateAlarm operation to create an event-triggered task for services that experience bursty or unpredictable traffic. After you associate a Cloud Monitor metric with the task, you can dynamically adjust the number of Elastic Compute Service (ECS) instance or Elastic Container Instance (ECI) in your scaling group and monitor instance metrics in real time. This helps you better manage and maintain your cloud resources.

Usage notes

  • If you create an event-triggered task of the custom monitoring type (MetricType=custom), you must first report your custom metrics to Cloud Monitor. For more information, see Event-triggered tasks for custom monitoring.

  • When you create an event-triggered task, you must specify the metric (MetricName) and dimensions (Dimension.N.DimensionKey and Dimension.N.DimensionValue) to define the aggregation scope for the metric data in the scaling group. For example, you can specify user_id and scaling_group to aggregate the metric data of all ECS or ECI instances that belong to a specific user and scaling group.

    • The metrics for an event-triggered task of the custom monitoring type (MetricType=custom) depend on your custom monitoring metrics.

    • For more information about the metrics supported for event-triggered tasks of the system monitoring type (MetricType=system), see Event-triggered tasks for system monitoring.

Note

In the dimension information, user_id and scaling_group are automatically populated. You must manually specify device and state. For more information, see the descriptions of the Dimension.N.DimensionKey and Dimension.N.DimensionValue parameters.

Test the operation

Run this operation in OpenAPI Explorer to skip the process of calculating signatures. After a successful call, OpenAPI Explorer automatically generates SDK sample code.

Request parameters

Parameter

Type

Required

Example

Description

Action

String

Yes

CreateAlarm

A required parameter. Set the value to CreateAlarm.

RegionId

String

Yes

cn-hangzhou

The region ID of the scaling group.

Name

String

No

TestAlarmTask

The name of the event-triggered task.

Description

String

No

Test alarm task.

The description of the event-triggered task.

ScalingGroupId

String

Yes

asg-bp18p2yfxow2dloq****

The ID of the scaling group associated with the event-triggered task.

MetricName

String

No

CpuUtilization

The name of the metric. The valid values vary based on the metric type of the event-triggered task.

  • If the metric type is custom monitoring (MetricType=custom), the value is the name of your custom metric.

  • If the metric type is system monitoring (MetricType=system), the valid values are as follows:

    • CpuUtilization: (ECS) The CPU utilization. Unit: %.

    • ConcurrentConnections: (ECS) The number of concurrent connections.

    • IntranetTx: (ECS) The outbound traffic over the internal network. Unit: Kbit/min.

    • IntranetRx: (ECS) The inbound traffic over the internal network. Unit: Kbit/min.

    • VpcInternetTx: (ECS) The outbound traffic over the Internet from a VPC. Unit: Kbit/min.

    • VpcInternetRx: (ECS) The inbound traffic over the Internet to a VPC. Unit: Kbit/min.

    • SystemDiskReadBps: (ECS) The read BPS of the system disk. Unit: bytes/s.

    • SystemDiskWriteBps: (ECS) The write BPS of the system disk. Unit: bytes/s.

    • SystemDiskReadOps: (ECS) The read IOPS of the system disk. Unit: counts/s.

    • SystemDiskWriteOps: (ECS) The write IOPS of the system disk. Unit: counts/s.

    • CpuUtilizationAgent: (Agent) The CPU utilization. Unit: %.

    • GpuUtilizationAgent: (Agent) The GPU utilization. Unit: %.

    • GpuMemoryFreeUtilizationAgent: (Agent) The percentage of free GPU memory.

    • GpuMemoryUtilizationAgent: (Agent) The GPU memory usage. Unit: %.

    • MemoryUtilization: (Agent) The memory usage. Unit: %.

    • LoadAverage: (Agent) The average system load.

    • TcpConnection: (Agent) The total number of TCP connections.

    • TcpConnection: (Agent) The number of established TCP connections.

    • PackagesNetOut: (Agent) The number of packets sent over the internal NIC. Unit: packets/s.

    • PackagesNetIn: (Agent) The number of packets received by the internal NIC. Unit: packets/s.

    • PackagesNetOut: (Agent) The number of packets sent over the public NIC. Unit: packets/s.

    • PackagesNetIn: (Agent) The number of packets received by the public NIC. Unit: packets/s.

    • EciPodCpuUtilization: The CPU utilization. Unit: %.

    • EciPodMemoryUtilization: The memory usage. Unit: %.

    • LoadBalancerRealServerAverageQps: (ALB) The QPS of a single server in the server group. Unit: queries/s.

For more information, see Event-triggered tasks for system monitoring.

MetricType

String

No

system

The type of the metric. Valid values:

  • system: Use Cloud Monitor system metrics.

  • custom: Use custom metrics reported to Cloud Monitor.

Period

Integer

No

300

The statistical period for the metric. Unit: seconds. Valid values:

  • 15

  • 60

  • 120

  • 300

  • 900

Note

A statistical period of 15 seconds is supported only for scaling groups of the ECS type.

Default value: 300.

Statistics

String

No

Average

The method used to aggregate statistics for the metric. Valid values:

  • Average

  • Minimum

  • Maximum

Default value: Average.

Threshold

Float

No

80.0

The threshold of the metric. A scaling rule is executed if the threshold is met for a specified number of times.

ComparisonOperator

String

No

>=

The comparison operator used to compare the metric value and the threshold. Valid values:

  • >=: greater than or equal to.

  • <=: less than or equal to.

  • >: greater than.

  • <: less than.

Default value: >=.

EvaluationCount

Integer

No

3

The number of consecutive times the threshold must be met before a scaling rule is executed. For example, if you set this parameter to 3, a scaling rule is executed only if the average CPU utilization is greater than or equal to 80% for three consecutive statistical periods.

Default value: 3.

GroupId

Integer

No

4055401

The ID of the Cloud Monitor application group to which the custom metric belongs. This parameter is required only when MetricType is set to custom.

Effective

String

No

TZ=+00 * * 1-2 * * ?

The effective period of the event-triggered task. By default, the task is always active.

This parameter follows the cron expression. The default format is X X X X X ?. The meaning is as follows:

  • cron expression: The task is always active.

  • * * 17-18 * * ? : The task is active from 17:00 to 18:59 (UTC+8) every day.

Note

The value of this parameter defaults to the UTC+8 time zone. You can specify a time zone by adding TZ=+yy before the cron expression, where yy represents the numerical value of the time zone. For example, TZ=+00 * * 1-2 * * ? indicates that the event-triggered task takes effect from 01:00 to 02:59 every day in the UTC+0 time zone.

Sample values:

  • * * * * * ? : Always active.

  • * * 17-18 * * ? : Active every day from 17:00 to 18:59 in the UTC+8 time zone.

  • TZ=+00 * * 1-2 * * ?: Active every day from 01:00 to 02:59 in the UTC+0 time zone.

AlarmAction.N

String

No

ari:acs:ess:cn-hangzhou:1406926****:scalingrule/asr-bp163l21e07uhn****

The unique identifier of scaling rule N that is associated with the event-triggered task.

Dimension.N.DimensionKey

String

No

device

The key of dimension N for the metric. The valid values vary based on the metric type.

  • If MetricType is set to custom, you can specify this parameter as needed.

  • If MetricType is set to system, the valid values are as follows:

    • user_id: The ID of your Alibaba Cloud account.

    • scaling_group: The scaling group that is monitored.

    • device: The type of the NIC.

    • state: The state of the TCP connection.

    • rulePool: The server group specified for the QPS metric of an ALB.

Dimension.N.DimensionValue

String

No

eth0

The value of dimension N for the metric. The valid values vary based on the value of Dimension.N.DimensionKey.

  • If Dimension.N.DimensionKey is a custom value (MetricType=custom), you can specify this parameter as needed.

  • If Dimension.N.DimensionKey is a system-defined value (MetricType=system), the valid values are as follows:

    • user_id: Automatically filled by the system.

    • scaling_group: Automatically filled by the system.

    • device:

      • eth0: For classic network instances, eth0 represents the internal NIC. For VPC-connected instances, only the eth0 NIC exists.

      • eth1: For classic network instances, eth1 represents the public NIC.

    • state:

      • TCP_TOTAL: The total number of TCP connections.

      • ESTABLISHED: The number of established TCP connections.

    • rulePool: The ID of an ALB server group. Example: sgp-xxxxx.

Expression.N.MetricName

String

No

CpuUtilization

The name of metric N in a multi-metric alert rule. The valid values vary based on the metric type.

  • If the metric type is custom monitoring (MetricType=custom), the value is the name of your custom metric.

  • If the metric type is system monitoring (MetricType=system), the valid values are as follows:

    • CpuUtilization: (ECS) The CPU utilization. Unit: %.

    • ConcurrentConnections: (ECS) The number of concurrent connections.

    • IntranetTx: (ECS) The outbound traffic over the internal network. Unit: Kbit/min.

    • IntranetRx: (ECS) The inbound traffic over the internal network. Unit: Kbit/min.

    • VpcInternetTx: (ECS) The outbound traffic over the Internet from a VPC. Unit: Kbit/min.

    • VpcInternetRx: (ECS) The inbound traffic over the Internet to a VPC. Unit: Kbit/min.

    • SystemDiskReadBps: (ECS) The read BPS of the system disk. Unit: bytes/s.

    • SystemDiskWriteBps: (ECS) The write BPS of the system disk. Unit: bytes/s.

    • SystemDiskReadOps: (ECS) The read IOPS of the system disk. Unit: counts/s.

    • SystemDiskWriteOps: (ECS) The write IOPS of the system disk. Unit: counts/s.

    • CpuUtilizationAgent: (Agent) The CPU utilization. Unit: %.

    • GpuUtilizationAgent: (Agent) The GPU utilization. Unit: %.

    • GpuMemoryFreeUtilizationAgent: (Agent) The percentage of free GPU memory.

    • GpuMemoryUtilizationAgent: (Agent) The GPU memory usage. Unit: %.

    • MemoryUtilization: (Agent) The memory usage. Unit: %.

    • LoadAverage: (Agent) The average system load.

    • TcpConnection: (Agent) The total number of TCP connections.

    • TcpConnection: (Agent) The number of established TCP connections.

    • PackagesNetOut: (Agent) The number of packets sent over the internal NIC. Unit: packets/s.

    • PackagesNetIn: (Agent) The number of packets received by the internal NIC. Unit: packets/s.

    • PackagesNetOut: (Agent) The number of packets sent over the public NIC. Unit: packets/s.

    • PackagesNetIn: (Agent) The number of packets received by the public NIC. Unit: packets/s.

    • EciPodCpuUtilization: The CPU utilization. Unit: %.

    • EciPodMemoryUtilization: The memory usage. Unit: %.

    • LoadBalancerRealServerAverageQps: (ALB) The QPS of a single server in the server group. Unit: queries/s.

For more information, see Event-triggered tasks for system monitoring.

Expression.N.ComparisonOperator

String

No

>=

The comparison operator used to compare the metric value and the threshold in a multi-metric alert rule. Valid values:

  • >=: greater than or equal to.

  • <=: less than or equal to.

  • >: greater than.

  • <: less than.

Default value: >=.

Expression.N.Period

Integer

No

900

The statistical period for metric N in a multi-metric alert rule. Unit: seconds. Valid values:

  • 15

  • 60

  • 120

  • 300

  • 900

Note

A statistical period of 15 seconds is supported only for scaling groups of the ECS type.

Default value: 300.

Expression.N.Statistics

String

No

Average

The method used to aggregate statistics for metric N in a multi-metric alert rule. Valid values:

  • Average

  • Minimum

  • Maximum

Default value: Average.

Expression.N.Threshold

Float

No

40.0

The threshold of metric N in a multi-metric alert rule. A scaling rule is executed if the threshold is met for a specified number of times.

ExpressionsLogicOperator

String

No

&&

The relationship between the conditions of a multi-metric alert rule. Valid values:

  • &&: An alert is triggered only when all metrics meet their alert conditions. This means that all expressions in the multi-metric alert rule must evaluate to true.

  • ||: An alert is triggered if any one of the metrics meets its alert condition.

Default value: &&.

Response parameters

Parameter

Type

Example

Description

AlarmTaskId

String

asg-bp1hvbnmkl10vll5****_f95ce797-dc2e-4bad-9618-14fee7d1****

The ID of the event-triggered task.

RequestId

String

473469C7-AA6F-4DC5-B3DB-A3DC0DE3****

The ID of the request.

Examples

Sample request

http(s)://ess.aliyuncs.com/?Action=CreateAlarm
&RegionId=cn-hangzhou
&Name=TestAlarmTask
&Description=Test alarm task.
&ScalingGroupId=asg-bp18p2yfxow2dloq****
&MetricName=CpuUtilization
&MetricType=system
&Period=300
&Statistics=Average
&Threshold=80.0
&ComparisonOperator=>=
&EvaluationCount=3
&GroupId=4055401
&Effective=TZ=+00 * * 1-2 * * ?
&AlarmAction=["ari:acs:ess:cn-hangzhou:1406926****:scalingrule/asr-bp163l21e07uhn****"]
&Dimension=[{"DimensionKey":"device","DimensionValue":"eth0"}]
&Expression=[{"MetricName":"CpuUtilization","ComparisonOperator":">=","Period":900,"Statistics":"Average","Threshold":40.0}]
&ExpressionsLogicOperator=&&
&Common request parameters

Sample response

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<CreateAlarmResponse>
    <AlarmTaskId>asg-bp1hvbnmkl10vll5****_f95ce797-dc2e-4bad-9618-14fee7d1****</AlarmTaskId>
    <RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3****</RequestId>
</CreateAlarmResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "AlarmTaskId" : "asg-bp1hvbnmkl10vll5****_f95ce797-dc2e-4bad-9618-14fee7d1****",
  "RequestId" : "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****"
}

Error codes

For more error codes, visit the Error Center.

HTTP status code

Error code

Error message

Description

404

InvalidParameter

The specified value of parameter "%s" is not valid.

The value of the %s parameter is invalid.