Creates event-triggered tasks. If your business encounters unexpected traffic surges or has no specific patterns, you can call the CreateAlarm operation to create an event-triggered task and associate a CloudMonitor metric with the task. This allows you to dynamically adjust the number of Elastic Compute Service (ECS) instances or elastic container instances in your scaling group and keep updated on the real-time metric data, which facilitates cloud resource management and maintenance.
Usage notes
If you set MetricType to custom, you must report your custom metrics to CloudMonitor before you can create event-triggered tasks by using the custom metrics. For more information, see Event-triggered tasks of the custom monitoring type.
When you create an event-triggered task, you must specify MetricName, Dimension.N.DimensionKey, and Dimension.N.DimensionValue to determine the range of statistics that you want to aggregate for the metrics of the scaling group. For example, you can specify user_id and scaling_group to aggregate monitoring data of all Elastic Compute Service (ECS) instances in a scaling group within an Alibaba Cloud account.
If you create an event-triggered task of the custom monitoring type, you can associate only custom metrics with the task.
If you create an event-triggered task of the system monitoring type, you can associate the system metrics described in Event-triggered tasks of the system monitoring type with the task.
user_id and scaling_group are automatically populated. You need to only specify device and state. For more information, see Dimension.N.DimensionKey
and Dimension.N.DimensionValue
in the "Request parameters" section of this topic.
Debugging
Request parameters
Parameter | Type | Required | Example | Description |
Action | String | Yes | CreateAlarm | The operation that you want to perform. 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 for which you want to create the event-triggered task. |
MetricName | String | No | CpuUtilization | The metric name. The valid values of MetricName vary based on the value of MetricType.
For more information, see Event-triggered tasks of the system monitoring type. |
MetricType | String | No | system | The metric type. Valid values:
|
Period | Integer | No | 300 | The statistical period of the metric data. Unit: seconds. Valid values:
Note You can set the value of this parameter to 15 seconds only for scaling groups of the ECS type. Default value: 300. |
Statistics | String | No | Average | The method that you want to use to aggregate the metric data. Valid values:
Default value: Average. |
Threshold | Float | No | 80.0 | The threshold of the metric. If the threshold is reached the specified number of times during the statistical period, a scaling rule is executed. |
ComparisonOperator | String | No | >= | The operator that you want to use to compare the metric value and the threshold.
Default value: >=. |
EvaluationCount | Integer | No | 3 | The number of times that the threshold must be reached before a scaling rule is executed. For example, if you set this parameter to 3, the average CPU utilization must reach 80% three times in a row before a scaling rule is triggered. Default value: 3. |
GroupId | Integer | No | 4055401 | The ID of the CloudMonitor application group to which the custom metric belongs. This parameter is required only if you set MetricType to custom. |
Effective | String | No | TZ=+00 * * 1-2 * * ? | The effective period of the event-triggered task. By default, the event-triggered task is in effect at all times. This parameter follows the cron expression format. The default format is
Note By default, the value of this parameter is specified in UTC+8. You can specify the time zone before a cron expression in the Examples:
|
AlarmAction.N | String | No | ari:acs:ess:cn-hangzhou:1406926****:scalingrule/asr-bp163l21e07uhn**** | The unique identifier of scaling rule N that you want to associate with the event-triggered task. |
Dimension.N.DimensionKey | String | No | device | The key of dimension N that you want to associate with the metric. The valid values of Dimension.N.DimensionKey vary based on the value of MetricType.
|
Dimension.N.DimensionValue | String | No | eth0 | The value of dimension N that you want to associate with the metric. The valid values of Dimension.N.DimensionValue vary based on the value of Dimension.N.DimensionKey.
|
Expression.N.MetricName | String | No | CpuUtilization | The names of the metrics in the multi-metric alert rule. The valid values of MetricName vary based on the value of MetricType.
For more information, see Event-triggered tasks of the system monitoring type. |
Expression.N.ComparisonOperator | String | No | >= | The operator that you want to use to compare the metric value and the threshold in the multi-metric alert rule. Valid values:
Default value: >=. |
Expression.N.Period | Integer | No | 900 | The statistical period of metric data in the multi-metric alert rule. Unit: seconds. Valid values:
Note You can set the value of this parameter to 15 seconds only for scaling groups of the ECS type. Default value: 300. |
Expression.N.Statistics | String | No | Average | The method that you want to use to aggregate the metric value in the multi-metric alert rule. Valid values:
Default value: Average. |
Expression.N.Threshold | Float | No | 40.0 | The thresholds of the metrics in the multi-metric alert rule. If the thresholds are reached the specified number of times within the statistical period, a scaling rule is executed. |
ExpressionsLogicOperator | String | No | && | The relationship between the trigger conditions in the 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 request ID. |
Examples
Sample requests
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 success responses
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 a list of error codes, see Service error codes.
HTTP status code | Error code | Error message | Description |
404 | InvalidParameter | The specified value of parameter "%s" is not valid. | The value of "%s" is invalid. |