SDK使用手册
前置条件:
需要安装有python2.7版本
安装pip
如果已有pip或者使用其他方案,可忽略此步骤。
如何安装pip
命令行工具 CLI,如果已安装,请略过:
- [backcolor=transparent]pip install aliyuncli
- [backcolor=transparent]pip install [backcolor=transparent]-[backcolor=transparent]Iv[backcolor=transparent] aliyun[backcolor=transparent]-[backcolor=transparent]python[backcolor=transparent]-[backcolor=transparent]sdk[backcolor=transparent]-[backcolor=transparent]cms[backcolor=transparent]==[backcolor=transparent]5.0[backcolor=transparent].[backcolor=transparent]0
- [backcolor=transparent]aliyuncli configure
命令行工具 CLI 安装说明
安装cms-python-sdk的依赖:
- [backcolor=transparent]pip install aliyun[backcolor=transparent]-[backcolor=transparent]python[backcolor=transparent]-[backcolor=transparent]sdk[backcolor=transparent]-[backcolor=transparent]core
- [backcolor=transparent]pip install aliyun[backcolor=transparent]-[backcolor=transparent]python[backcolor=transparent]-[backcolor=transparent]sdk[backcolor=transparent]-[backcolor=transparent]cms
code示例:
- [backcolor=transparent]from[backcolor=transparent] aliyunsdkcore [backcolor=transparent]import[backcolor=transparent] client
- [backcolor=transparent]from[backcolor=transparent] aliyunsdkcms[backcolor=transparent].[backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]v20170301 [backcolor=transparent]import[backcolor=transparent] [backcolor=transparent]QueryMetricListRequest
- [backcolor=transparent]import[backcolor=transparent] time
- [backcolor=transparent]clt [backcolor=transparent]=[backcolor=transparent] client[backcolor=transparent].[backcolor=transparent]AcsClient[backcolor=transparent]([backcolor=transparent]'your_access_key'[backcolor=transparent],[backcolor=transparent]'your_access_secret'[backcolor=transparent],[backcolor=transparent]'your_region_id'[backcolor=transparent])
- [backcolor=transparent]request [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]QueryMetricListRequest[backcolor=transparent].[backcolor=transparent]QueryMetricListRequest[backcolor=transparent]()
- [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]set_accept_format[backcolor=transparent]([backcolor=transparent]'json'[backcolor=transparent])
- [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]set_Project[backcolor=transparent]([backcolor=transparent]'acs_ecs_dashboard'[backcolor=transparent])
- [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]set_Metric[backcolor=transparent]([backcolor=transparent]'CPUUtilization'[backcolor=transparent])
- [backcolor=transparent]start_time [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]"2016-10-25 10:00:00"
- [backcolor=transparent]timestamp_start [backcolor=transparent]=[backcolor=transparent] int[backcolor=transparent]([backcolor=transparent]time[backcolor=transparent].[backcolor=transparent]mktime[backcolor=transparent]([backcolor=transparent]time[backcolor=transparent].[backcolor=transparent]strptime[backcolor=transparent]([backcolor=transparent]start_time[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"%Y-%m-%d %H:%M:%S"[backcolor=transparent])))[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent] [backcolor=transparent]1000
- [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]set_StartTime[backcolor=transparent]([backcolor=transparent]timestamp_start[backcolor=transparent])
- [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]set_Dimensions[backcolor=transparent]([backcolor=transparent]"{'instanceId':'i-94g5hc378'}"[backcolor=transparent])
- [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]set_Period[backcolor=transparent]([backcolor=transparent]'60'[backcolor=transparent])
- [backcolor=transparent]result [backcolor=transparent]=[backcolor=transparent] clt[backcolor=transparent].[backcolor=transparent]do_action_with_exception[backcolor=transparent]([backcolor=transparent]request[backcolor=transparent])
- [backcolor=transparent]print[backcolor=transparent] result