Event-triggered tasks are a feature of Auto Scaling that uses CloudMonitor to dynamically manage scaling groups. Similar to a scheduled task, an event-triggered task triggers a specified scaling rule to perform a scaling activity, automatically adjusting the number of instances in a scaling group.
Event-triggered tasks
An event-triggered task monitors specific metrics and collects statistics on metric data in real time. When a statistic meets the specified alert conditions, an alert is triggered, and the corresponding scaling rule runs. You can use event-triggered tasks to adjust the number of instances in a scaling group in real time based on workload changes. This helps ensure that metric values stay within your desired range. Two types of event-triggered tasks are available:
System monitoring event-triggered task: A standardized task that allows you to select from predefined system metrics.
Custom monitoring event-triggered task: A customizable task that provides a standardized way to integrate your own monitoring system, making the feature more versatile.
Scheduled tasks run a specified scaling rule at a specified time. If your business workloads are predictable, you can create a scheduled task in advance. For more information, see Overview of scheduled tasks. However, for unpredictable scenarios such as traffic bursts, scheduled tasks may not meet your requirements. In contrast, event-triggered tasks offer more flexibility by responding to real-time workload changes, adding instances to a scaling group during peak hours to handle increased load, and removing instances during off-peak hours to reduce costs.
Limitations
If the expected number of instances feature is enabled for a scaling group, no other scaling activities can be performed while a non-parallel scaling activity is in progress. For more information, see Expected number of instances.
A scaling rule in its cooldown period rejects trigger requests from an event-triggered task.
After a new ECS instance or ECI instance is added to a scaling group, it takes some time (typically several minutes) to start, complete system configuration, deploy your application, and collect monitoring data. Therefore, you must set an appropriate cooldown period based on your specific business scenario to prevent the scaling rule from being repeatedly triggered before monitoring data from the new instance is available.
By default, an event-triggered task has a one-minute silence period (statistical period). This means that after an alert is triggered, the scaling rule is not triggered again within one minute.
Cron expression
When you configure an event-triggered task in the Auto Scaling console, you can set the Effective Period parameter using a Cron expression.
A Cron expression is a string that represents a schedule. The string consists of space-separated fields. Auto Scaling supports Cron expressions with five fields in the X X X X X format, where X is a placeholder for a field. The fields, in order, represent second, minute, hour, day of the month, and month. Each field can be a specific value or a special character with a logical meaning.
When you configure a Cron expression for an event-triggered task, note the following:
Cron expressions use the UTC+0 time zone. When you configure a Cron expression, you must convert your local time to UTC+0. For example, the time zone in China is UTC+8. If you want a task to be effective daily from 01:00 to 02:59 China Standard Time, you must subtract 8 hours. The corresponding Cron expression is
* * 17-18 * *.If an alert is triggered outside the effective period of an event-triggered task, the task displays the alert status but does not execute the alert trigger rule.
Table 1. Field values
Field | Required | Value range | Special character |
Second | Yes | 0 to 59 | , - / * |
Minute | Yes | 0 to 59 | , - / * |
Hour | Yes | 0 to 23 | , - / * |
Day of month | Yes | 1 to 31 | , - / * L W |
Month | Yes | 1 to 12 | , - / * |
Table 2. Special characters
Special character | Description | Example |
| All possible values in the field. | In the Month field, |
| A list of enumerated values. | In the Minute field, |
| A range of values. | In the Minute field, |
| An increment of a value. | In the Minute field, |
| Indicates the last day of the month. This character is supported only in the Day of month field. Note When you specify the | In the Day of month field, |
| Represents a weekday. The event is triggered on the weekday nearest to the specified day. The | In the Day of month field, if you specify |
Table 3. Examples
The following table shows how UTC+0 Cron expressions translate to effective times in the UTC+8 time zone. Always define Cron expressions in UTC+0.
Example | Description |
| Effective at all times. |
| Effective from 01:00 to 01:30 and from 02:00 to 02:30 every day. |
| Effective from 00:00 to 00:59 and from 02:00 to 02:59 every day. |
| Effective from 01:00 to 01:59 every two days, starting from the first day of the month. For example, the first two effective periods of each month are 01:00-01:59 on the 1st and 01:00-01:59 on the 3rd. |
| Effective from 01:00 to 01:59 on the last day of each month. |
| The effective time varies based on whether the 5th of the month is a weekday:
|
Table 4. Examples
The following table provides examples of Cron expressions in the UTC+0 time zone. When you set a Cron expression, make sure to convert your local time to UTC+0 if necessary.
Configure event-triggered tasks
The following table describes how to manage event-triggered tasks for a scaling group.
Console guide | Description | API reference |
Create an event-triggered task | ||
View event-triggered tasks | ||
Modify or delete an event-triggered task | ||
Disable or enable an event-triggered task |