本文简要介绍了Python SDK的安装方法,并提供了示例代码。

背景信息

  • OpenAPI开发者门户提供在线调试API和动态生成SDK示例代码的功能,能显著降低API的使用难度,推荐您使用。
  • 关于云监控API详情,请参见API概览

Python SDK安装

关于Python SDK的安装方法。具体操作,请参见快速开始

Python SDK安装包下载地址如下:

Python SDK示例

#!/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'))