This topic describes how to install Cloud Monitor SDK for Python and provides sample code.

Background information

Install Cloud Monitor SDK for Python

For more information about how to install Cloud Monitor SDK for Python, see Quick start.

You can download the installation packages of the SDKs for Python from the following links:

Sample code

#!/usr/bin/env python
#coding=utf-8

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcms.request.v20190101.DescribeMetricListRequest import DescribeMetricListRequest

client = AcsClient('<accessKeyId>', '<accessSecret>', 'cn-beijing')

request = DescribeMetricListRequest()
request.set_accept_format('json')

request.set_StartTime("2019-05-21 10:00:00")
request.set_Dimensions("{\"instanceId\":\"i-2ze3*******\"}")
request.set_Period("60")
request.set_Namespace("acs_ecs_dashboard")
request.set_MetricName("CPUUtilization")

response = client.do_action_with_exception(request)
# python2:  print(response)
print(str(response, encoding='utf-8'))