Skip to content

Alibaba Cloud Spot Instance Survival Inspection

Background

Since the market price of spot instances fluctuates with supply and demand, it is necessary to specify a bidding model when creating a spot instance. A spot instance can only be successfully created when the real-time market price for the specified instance type is lower than the bid and the inventory is sufficient. Therefore, the inspection of cloud assets' spot instances becomes particularly important. Through inspections, when it is found that a spot instance is about to be released, it will prompt the latest prices of all available zones for the current specification of the spot instance as well as the historical prices of the spot instance and provide appropriate handling suggestions.

Prerequisites

  1. Offline deployment of DataFlux Func
  2. Enable the [Script Market] in self-built DataFlux Func(../script-market-basic-usage/)
  3. Create an API Key for operations in the "TrueWatch" "Management / API Key Management"
  4. Install the "Self-built Inspection Core Package", "Algorithm Library", and "Self-built Inspection (Alibaba Cloud Spot Instance Survival Detection)" through the "Script Market" in the self-built DataFlux Func
  5. Write a self-built inspection processing function in the self-built DataFlux Func
  6. Create a scheduled task (Old version: Automatic Trigger Configuration) for the written function through "Management / Scheduled Tasks (Old version: Automatic Trigger Configuration)" in the self-built DataFlux Func

If you consider using a cloud server for offline deployment of DataFlux Func, please ensure it is deployed with the currently used TrueWatch SaaS in the same operator and region

Configure Inspection

Create a new script set in the self-built DataFlux Func to enable the configuration of Alibaba Cloud Spot Instance Survival Inspection.

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from guance_monitor__runner import Runner
from guance_monitor__register import self_hosted_monitor
import guance_monitor_aliyun_spot_alive__main as spot_instance

API_KEY_ID  = 'xxxxx'
API_KEY     = 'xxxxx'

'''
Task configuration parameters should use:
@DFF.API('Alibaba Cloud Spot Instance Survival Inspection', fixed_crontab='*/2 * * * *', timeout=60)

fixed_crontab: Fixed execution frequency "every 2 minutes"
timeout: Task execution timeout duration, controlled within 1 minute
'''

@self_hosted_monitor(API_KEY_ID, API_KEY)
@DFF.API('Alibaba Cloud Spot Instance Survival Inspection', fixed_crontab='*/2 * * * *', timeout=60)
def run(configs=[]):
    """
    Parameters: instance_type
        configs:
            Configure the instance_type to be inspected (configuration type, can configure one or multiple) ecs.s6-c1m1.small
            Configure the spot_with_price_limit (accepted discount) 0.12

        Configuration example: You can configure multiple groups or a single one
        configs = [{"instance_type": "xxx1","spot_with_price_limit": "xxx2"}]

    """
    checkers = [
        spot_instance.SPOTInstanceCheck(configs=configs),
    ]

    Runner(checkers, debug=False).run()

Start Inspection

After configuring the inspection in DataFlux Func, you can test it by selecting the run() method directly on the page and running it. After clicking publish, you can view and configure it in the DataFlux Func "Management / Scheduled Tasks".

View Events

The inspection will generate corresponding events based on the status of the current spot instance. When a spot instance about to be released is discovered, Intelligent Inspection will generate relevant events, which can then be viewed in the "Event Center".

Event Details

  • Event Overview: Describes the object and content of the abnormal inspection event
  • Spot Instance Details: View detailed information about the current instance including instance name, ID, region, availability zone, etc.
  • Spot Instance Type Price: View the prices of all available zones under the current specification to assist users in bidding
  • Spot Instance Type Historical Price: View the historical prices of the spot instance under different available zones for the current specification to track price changes
  • Warm Suggestions: Provide operational suggestions for the current abnormal scenario

Common Issues

1. How to configure the detection frequency of Alibaba Cloud Spot Instance Survival Inspection

  • In the self-built DataFlux Func, add fixed_crontab='*/2 * * * *', timeout=60 in the decorator while writing the self-built inspection processing function, then configure it in "Management / Scheduled Tasks (Old version: Automatic Trigger Configuration)".

2. There may be no abnormal analysis when Alibaba Cloud Spot Instance Survival Inspection is triggered

When there is no abnormal analysis in the inspection report, check the data collection status of the current datakit.

3. During the inspection process, previously normally running scripts encounter abnormal errors

Update the referenced script sets in the Script Market of DataFlux Func. You can view the update records of the Script Market through the Change Log to facilitate timely updates to the scripts.