sort_py_cpu.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. '''
  4. 对instance数据按照cpu使用率降序排列
  5. @Auther :liuyuqi.gov@msn.cn
  6. @Time :8/13/2018 9:04 PM
  7. @File :sort_py_cpu.py
  8. '''
  9. import pandas as pd
  10. res = pd.DataFrame()
  11. appResources = pd.read_csv("../resb/app_resources.csv", header=None,
  12. names=list(["appid", "cpu", "mem", "disk", "P", "M", "PM"]), encoding="utf-8")
  13. instanceDeploy = pd.read_csv("../resb/instance_deploy.csv", header=None,
  14. names=list(["instanceid", "appid", "machineid"]), encoding="utf-8")
  15. instanceDeploy["cpu_avg"] = None
  16. tmp_cpu = appResources["cpu"].str.split('|', expand=True).astype('float')
  17. appResources["cpu_avg"] = tmp_cpu.T.mean().T
  18. h, l = instanceDeploy.shape
  19. print(h)
  20. # for i in range(0, h):
  21. # instanceDeploy["cpu_avg"][i] = appResources[appResources["appid"] == instanceDeploy["appid"][i]]["cpu_avg"].values[
  22. # 0]
  23. # if i % 1000==0:
  24. # print(i)
  25. # res["instanceid"] = instanceDeploy["instanceid"]
  26. # res["cpu"] = instanceDeploy["cpu_avg"]
  27. # res.sort_values(ascending=False, by="cpu", inplace=True)
  28. #
  29. # res.to_csv("../resb/app_cpu.csv", index=False, header=False)