This topic describes how to use Server Load Balancer (SLB) SDK for Python to collect monitoring metrics of an SLB instance and set alert rules.
Prerequisites
Before you run the following code in script mode, make sure that the following requirements
are met:
- An AccessKey ID and an AccessKey secret that are used for identity verification are created for your Alibaba Cloud account. For more information, see Obtain an AccessKey pair.
- The example library of CLB Python is downloaded. For more information, see CLB Python example library.
Go to the directory where the setup.py file is stored, and run the following command to initialize the environment:
python setup.py install
Background information
- Create an SLB instance in the China (Zhangjiakou) region. Set the name of the SLB instance to SLB1, set the primary zone to cn-zhangjiakou-a, and set the secondary zone to cn-zhangjiakou-b.
- Create a TCP listener for the SLB instance. Set the frontend port that the SLB instance uses to port 80 and set the backend port that receives requests to port 80. Then, set the health check protocol to TCP and add the ECS instances that are deployed in the China (Zhangjiakou) region to the default server group. Set the weights of both ECS instances to 100. Network traffic is then forwarded by the SLB instance to the ECS instances.
- Query the queries per second (QPS) usage of the new SLB instance.
- Create an alert rule. If the average QPS usage of the new SLB instance is at least 35, the alert is triggered.
- Delete the SLB instance.