需要安装有python2.7版本。

安装pip

如果已有pip或者使用其他方案,可忽略此步骤。

如何安装pip

命令行工具 CLI(如果已安装,请略过):

pip install aliyuncli
pip install -Iv aliyun-python-sdk-cms==5.0.0
aliyuncli configure

命令行工具 CLI 安装说明

安装cms-python-sdk的依赖

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

最新版Python SDK

code示例

from aliyunsdkcore import client
from aliyunsdkcms.request.v20180308 import QueryMetricListRequest
import time
clt = client.AcsClient('your_access_key','your_access_secret','your_region_id')
request = QueryMetricListRequest.QueryMetricListRequest()
request.set_accept_format('json')
request.set_Project('acs_ecs_dashboard')
request.set_Metric('CPUUtilization')
start_time = "2016-10-25 10:00:00"
timestamp_start = int(time.mktime(time.strptime(start_time, "%Y-%m-%d %H:%M:%S"))) * 1000
request.set_StartTime(timestamp_start)
request.set_Dimensions("{'instanceId':'i-94g5hc378'}")
request.set_Period('60')
result = clt.do_action_with_exception(request)
print result