开发者社区> 问答> 正文

云监控PythonSDK使用手册

反向一觉 2017-10-31 14:07:36 1179

SDK使用手册
前置条件:
需要安装有python2.7版本
安装pip
如果已有pip或者使用其他方案,可忽略此步骤。
如何安装pip
命令行工具 CLI,如果已安装,请略过:

  1. [backcolor=transparent]pip install aliyuncli
  2. [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
  3. [backcolor=transparent]aliyuncli configure

命令行工具 CLI 安装说明

安装cms-python-sdk的依赖:

  1. [backcolor=transparent]pip install aliyun[backcolor=transparent]-[backcolor=transparent]python[backcolor=transparent]-[backcolor=transparent]sdk[backcolor=transparent]-[backcolor=transparent]core
  2. [backcolor=transparent]pip install aliyun[backcolor=transparent]-[backcolor=transparent]python[backcolor=transparent]-[backcolor=transparent]sdk[backcolor=transparent]-[backcolor=transparent]cms

code示例:
  1. [backcolor=transparent]from[backcolor=transparent] aliyunsdkcore [backcolor=transparent]import[backcolor=transparent] client
  2. [backcolor=transparent]from[backcolor=transparent] aliyunsdkcms[backcolor=transparent].[backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]v20170301 [backcolor=transparent]import[backcolor=transparent] [backcolor=transparent]QueryMetricListRequest
  3. [backcolor=transparent]import[backcolor=transparent] time
  4. [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])
  5. [backcolor=transparent]request [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]QueryMetricListRequest[backcolor=transparent].[backcolor=transparent]QueryMetricListRequest[backcolor=transparent]()
  6. [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]set_accept_format[backcolor=transparent]([backcolor=transparent]'json'[backcolor=transparent])
  7. [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]set_Project[backcolor=transparent]([backcolor=transparent]'acs_ecs_dashboard'[backcolor=transparent])
  8. [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]set_Metric[backcolor=transparent]([backcolor=transparent]'CPUUtilization'[backcolor=transparent])
  9. [backcolor=transparent]start_time [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]"2016-10-25 10:00:00"
  10. [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
  11. [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]set_StartTime[backcolor=transparent]([backcolor=transparent]timestamp_start[backcolor=transparent])
  12. [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]set_Dimensions[backcolor=transparent]([backcolor=transparent]"{'instanceId':'i-94g5hc378'}"[backcolor=transparent])
  13. [backcolor=transparent]request[backcolor=transparent].[backcolor=transparent]set_Period[backcolor=transparent]([backcolor=transparent]'60'[backcolor=transparent])
  14. [backcolor=transparent]result [backcolor=transparent]=[backcolor=transparent] clt[backcolor=transparent].[backcolor=transparent]do_action_with_exception[backcolor=transparent]([backcolor=transparent]request[backcolor=transparent])
  15. [backcolor=transparent]print[backcolor=transparent] result

监控 开发工具 Python
分享到
取消 提交回答
全部回答(0)

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题