2
0

kis.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- encoding:utf-8 -*-
  2. import json,pprint
  3. from prettyprinter import prettyPrinter
  4. from kscore.session import get_session
  5. import json
  6. if __name__ == "__main__":
  7. s = get_session()
  8. ak = "your AK"
  9. sk = "your SK"
  10. kis_client = s.create_client("kis", "cn-beijing-6", "2018-09-01", True, None, None, ak, sk)
  11. # 列出region
  12. regions = kis_client.list_region()
  13. # prettyPrinter().pprint(regions)
  14. # 列出Idc
  15. idcs = kis_client.list_idc()
  16. prettyPrinter().pprint(idcs)
  17. # 查询各机房内机柜
  18. for idc in idcs["Data"]:
  19. devices = kis_client.get_cabinet(Idc=idc["Name"], Limit=-1)
  20. if devices["Total"] > 0:
  21. prettyPrinter().pprint(devices)
  22. # 查询带宽
  23. instances = []
  24. for idc in idcs["Data"]:
  25. bds = kis_client.get_bandwidth(Idc=idc["Name"], Limit=-1)
  26. if bds["Total"] > 0:
  27. # prettyPrinter().pprint(bds)
  28. for bd in bds["Data"]:
  29. instances.append(bd["InstanceId"])
  30. # prettyPrinter().pprint(instances)
  31. # 比如带宽实例如下:
  32. # [edca6c2e-4826-4a7d-b14b-01aba8a109b8,6e8a010a-d498-4f46-9d70-ad71f1fdc3e3]
  33. # 查询流量:粒度60秒,从 2018-09-06 10:00:00 到 2018-09-06 12:00:00
  34. resp = kis_client.get_monitor_data(InstanceId="edca6c2e-4826-4a7d-b14b-01aba8a109b8", Step=60, StartTime="2018-09-06 10:00:00", EndTime="2018-09-06 12:00:00")
  35. prettyPrinter().pprint(resp)