ProcessCpuUseage.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # coding: utf-8
  2. from DYProcessManager import ComponentStatus
  3. from component_controler import *
  4. class ComponentsLoad():
  5. def __init__(self):
  6. self.Process = ComponentStatus()
  7. def get_local_components_name(self):
  8. self.local_components_name = []
  9. for component_name in self.Process.components:
  10. self.local_components_name.append(component_name)
  11. for msgserver_num in self.Process.msgserver:
  12. msgserver_name = 'MsgServer' + str(msgserver_num)
  13. self.local_components_name.append(msgserver_name)
  14. return self.local_components_name
  15. def getload(self,types):
  16. for component_nanme in self.local_components_name:
  17. component = Action(component_nanme)
  18. component_status = component.isalived()
  19. if component_status:
  20. if types == 'cpu':
  21. print component_nanme,component_status.cpu_percent(interval=1)
  22. elif types == 'mem':
  23. print component_nanme,component_status.memory_info()
  24. elif types == 'io':
  25. print component_nanme,component_status.io_counters()
  26. elif types == 'conns':
  27. print component_nanme,component_status.connections()
  28. if __name__ == '__main__':
  29. loads = ComponentsLoad()
  30. loads.get_local_components_name()
  31. if len(sys.argv) == 2:
  32. types = sys.argv[1]
  33. type_range = ['cpu', 'mem', 'io', 'conns']
  34. for each_type in type_range:
  35. if types == each_type:
  36. loads.getload(types)
  37. if types not in type_range:
  38. print 'Illegal Segment! Now Exit...'
  39. sys.exit(1)
  40. else:
  41. loads.getload('cpu')