This topic describes how to install and use Cloud Monitor SDK for Python.

Before you install Cloud Monitor SDK for Python, make sure that Python 2.7 is installed on your computer.

Install pip

If you have installed pip or another package management system, skip this step.

For more information about how to install pip, see Install pip.

Install the SDK

pip install aliyun-python-sdk-core
pip install aliyun-python-sdk-cms

Latest version of the SDK for Python

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'))