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_idandscaling_groupto 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.
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
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.
For more information, see Event-triggered tasks for system monitoring. |
MetricType | String | No | system | The type of the metric. Valid values:
|
Period | Integer | No | 300 | The statistical period for the metric. Unit: seconds. Valid values:
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:
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:
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
Note The value of this parameter defaults to the UTC+8 time zone. You can specify a time zone by adding Sample values:
|
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.
|
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.
|
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.
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:
Default value: >=. |
Expression.N.Period | Integer | No | 900 | The statistical period for metric N in a multi-metric alert rule. Unit: seconds. Valid values:
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:
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:
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 parametersSample 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. |