Event-triggered tasks

更新时间:
复制 MD 格式

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:

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, * means every month.

,

A list of enumerated values.

In the Minute field, 5,20 specifies the 5th and 20th minute.

-

A range of values.

In the Minute field, 5-20 specifies every minute from the 5th minute to the 20th minute, inclusive.

/

An increment of a value.

In the Minute field, 0/15 specifies every 15 minutes, starting from the 0th minute. 3/20 specifies every 20 minutes, starting from the 3rd minute.

L

Indicates the last day of the month. This character is supported only in the Day of month field.

Note

When you specify the L character, do not specify a list or range. Otherwise, logical errors may occur.

In the Day of month field, L indicates the last day of the month.

W

Represents a weekday. The event is triggered on the weekday nearest to the specified day. The W character finds the nearest weekday within the current month.

In the Day of month field, if you specify 5W and the 5th is a Saturday, the task is triggered on Friday the 4th. If the 5th is a Sunday, the task is triggered on Monday the 6th. If the 5th is a weekday, the task is triggered on the 5th.

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.

* 0-30 17-18 * *

Effective from 01:00 to 01:30 and from 02:00 to 02:30 every day.

* * 16,18 * *

Effective from 00:00 to 00:59 and from 02:00 to 02:59 every day.

* * 17 1/2 *

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.

* * 17 L *

Effective from 01:00 to 01:59 on the last day of each month.

* * 17 5W *

The effective time varies based on whether the 5th of the month is a weekday:

  • If the 5th is a weekday (Monday to Friday): Effective from 01:00 to 01:59 on the 5th of the month.

  • If the 5th is a Saturday: Effective from 01:00 to 01:59 on the 4th of the month.

  • If the 5th is a Sunday: Effective from 01:00 to 01:59 on the 6th of the month.

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

Configure an event-triggered task

Create an event-triggered task

CreateAlarm

View event-triggered tasks

DescribeAlarms

Modify or delete an event-triggered task

Disable or enable an event-triggered task