app.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. # [9338 rows x 98 columns]
  32. df1["cpu_avg"] = tmp.T.mean().T # 转置,求均值,再转置回来,这样求得一行的均值。
  33. tmp = df1["mem"].str.split('|', expand=True).astype('float')
  34. df1["mem_avg"] = tmp.T.mean().T # 转置,求均值,再转置回来,这样求得一行的均值。
  35. print(df1.head())
  36. print("总共应用:", df1["appid"].unique().shape)
  37. df1.pop("cpu")
  38. df1.pop("mem")
  39. df1.to_csv("../data/app.csv")