Alibaba Cloud Elastic Compute Service (ECS) provides users with preemptible instances with a big discount of up to 90% off. If you configure a preemptible instance template in a scaling group, a preemptible instance is automatically created when a scale-out event of the scaling group is triggered. However, do you often worry about price changes of preemptible instances that are automatically scaled out? Are you frustrated when you find that the expenses exceed your psychological threshold at certain time points when you settle your monthly bills? Now, we provide a simpler solution that allows you to monitor the price changes of instance types in a scaling group and get notified of the changes in a timely manner. This topic describes how to monitor real-time prices and discounts of preemptible instances in a scaling group.

Procedure

Step 1: Activate OOS

1.1 Log on to the Alibaba Cloud Management Console. Search for the keywords Operation Orchestration and click Operation Orchestration Service that appears to go to the welcome page of Operation Orchestration Service (OOS).

1.2 Click Scheduled O&M in the left-side navigation pane.

No additional payment is required to activate OOS.

Step 2: Configure a scheduled task

2.1 Set the scheduled task type.

On the Scheduled O&M page, click Create. On the Create Scheduled O&M page, select Executed Periodically for Scheduled Task Type.

2.2 Set the execution frequency.

Set the execution frequency based on your business requirements. Standard crontab expressions are supported. The prices of spot instances do not change frequently within a short period of time. To prevent throttling caused by frequent requests, we recommend that you set an interval that is from 50 minutes to 1 hour. This helps you gain a full insight into price changes. The following figure shows an example.

2.3 Set the time zone for periodic execution.

Use the default value if you do not have special requirements.

2.4 Set the end time for periodic execution.

Set the end time for price monitoring based on your business requirements.

2.5 Preview the upcoming execution time.

Step 3: Select a template

Enter the keyword Alarm or the template name ACS-ECS-AlarmWhenDiscountOrSpotPriceExceedsThresholdByScalingGroup to search for the target template.

Step 4: Set template parameters

4.1 Select the target region.

Select the region of the scaling group you want to monitor. You can specify only one region. If you need to monitor multiple regions, configure a scheduled O&M task for each region.

4.2 Specify the scaling group.

Enter the ID of the scaling group to be monitored. The template can monitor multiple scaling groups at a time.

4.3 Set the monitoring task type.

Two types of monitoring tasks are supported:

  • Discount: monitors a scaling group based on real-time discounts. Assume that ECS instances of the ecs.c6.large type are configured in a scaling group. The original price of the instance type is USD 0.39 per hour and the spot instance price is USD 0.071 per hour. In this case, the discount for the spot instance is 82%, which is calculated based on the following formula: 1 - 0.071/0.39 = 0.82. Select this monitoring task type if you need to receive an alarm when the discount for the instance type is higher than a specified threshold, for example, 80% off.
  • Price: monitors a scaling group based on real-time prices. Assume that ECS instances of the ecs.c6.large type are configured in a scaling group. The original price of the instance type is USD 0.39 per hour and the spot instance price is USD 0.071 per hour. Select this monitoring task type if you need to receive an alarm when the price of the instance type is lower than a specified threshold, for example, USD 0.1 per hour.

4.4 Set a price or discount threshold.

  • If you select Discount as the monitoring type, set a discount threshold of the integer type.
  • If you require a price that is 5% of the original price, fill in 5.
  • If you require a price that is 11% of the original price, fill in 11.
  • If you require a price that is 32% of the original price, fill in 32.
  • The rest may be deduced by analogy.
  • If you select Price as the monitoring type, set a hourly price threshold, for example, 0.1.

4.5 Set a webhook URL that receives alarm notifications.

This section uses a DingTalk chatbot as an example.

4.5.1 Add a chatbot by choosing the following menu path in DingTalk:

Group Settings > Group Assistant > Add Robot > Custom > Add

4.5.2 Add the custom keyword Monitoring.

4.5.3 Copy the webhook URL of the chatbot.

4.5.4 Paste the webhook URL here.

4.6 Configure an authorized RAM role.

4.6.1 Log on to the Resource Access Management (RAM) console.

4.6.2 Select the authorization type.

4.6.3 Configure a RAM role.

We recommend that you set the role name to OOSServiceRole to facilitate management.

4.6.4 Authorize the RAM role.

4.6.5 Grant the required permission to the RAM role.

Grant the AliyunECSReadOnlyAccess permission to the RAM role.

4.6.6 Complete the configuration.

Return to the OOS configuration page, refresh the authorized role list, and then select OOSServiceRole to complete the configuration.

For more information about fine-grained authorization control, see https://help.aliyun.com/document_detail/120810.html.

Step 5: Execute the task and verify the alarm information

  1. Confirm the execution plan.
  2. Verify the alarm information.

To facilitate debugging, we recommend that you set a lower threshold in step 4.4 "Set a price or discount threshold." After you verify that you can receive alarm notifications, change the threshold to recreate an execution based on your business requirements. The following figure shows a sample of an alarm notification.