app.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. '''
  4. 对app表处理,计算平均CPU,mem,在app表添加两列保存其值
  5. @Auther :liuyuqi.gov@msn.cn
  6. @Time :2018/7/7 3:14
  7. @File :app.py
  8. '''
  9. import matplotlib
  10. matplotlib.use('Agg')
  11. # 数据预览
  12. import pandas as pd
  13. from configparser import ConfigParser
  14. # step1: 数据参数初始化
  15. cf = ConfigParser()
  16. config_path = "../conf/config.ini"
  17. section_name = "data_file_name"
  18. cf.read(config_path)
  19. app_interference = cf.get(section_name, "app_interference")
  20. app_resources = cf.get(section_name, "app_resources")
  21. instance_deploy = cf.get(section_name, "instance_deploy")
  22. machine_resources = cf.get(section_name, "machine_resources")
  23. # app表
  24. df1 = pd.read_csv(app_resources, header=None,
  25. names=list(["appid", "cpu", "mem", "disk", "P", "M", "PM"]), encoding="utf-8")
  26. # 新添加两列
  27. df1["cpu_avg"] = None
  28. df1["mem_avg"] = None
  29. # expand=True表示
  30. tmp = df1["cpu"].str.split('|', expand=True).astype('float')
  31. print(type(tmp))
  32. print(tmp.index)
  33. print(type(tmp[1]))
  34. exit(1)
  35. # [9338 rows x 98 columns]
  36. df1["cpu_avg"] = tmp.T.mean().T # 转置,求均值,再转置回来,这样求得一行的均值。
  37. tmp = df1["mem"].str.split('|', expand=True).astype('float')
  38. df1["mem_avg"] = tmp.T.mean().T # 转置,求均值,再转置回来,这样求得一行的均值。
  39. print(df1.head())
  40. print("总共应用:", df1["appid"].unique().shape)
  41. df1.pop("cpu")
  42. df1.pop("mem")
  43. df1.to_csv("../data/app.csv")