CPU_INFO

  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. from collections import OrderedDict
  4. import pprint
  5. def CPUinfo():
  6. ''' Return the information in /proc/CPUinfo
  7. as a dictionary in the following format:
  8. CPU_info['proc0']={...}
  9. CPU_info['proc1']={...}
  10. '''
  11. CPUinfo=OrderedDict()
  12. procinfo=OrderedDict()
  13. nprocs = 0
  14. with open('/proc/cpuinfo') as f:
  15. for line in f:
  16. if not line.strip():
  17. # end of one processor
  18. CPUinfo['proc%s' % nprocs] = procinfo
  19. nprocs=nprocs+1
  20. # Reset
  21. procinfo=OrderedDict()
  22. else:
  23. if len(line.split(':')) == 2:
  24. procinfo[line.split(':')[0].strip()] = line.split(':')[1].strip()
  25. else:
  26. procinfo[line.split(':')[0].strip()] = ''
  27. return CPUinfo
  28. if __name__=='__main__':
  29. CPUinfo = CPUinfo()
  30. for processor in CPUinfo.keys():
  31. print(CPUinfo[processor]['model name'])

Memory_info

  1. import cpuinfo,monitor
  2. CPUinfo = cpuinfo.CPUinfo()
  3. for processor in CPUinfo.keys():
  4. cpu = {"cpuinfo":CPUinfo[processor]['model name']}
  5. print (cpu)
  6. meminfo = monitor.meminfo()
  7. memToal = {"memToal": 'Total memory: {0}'.format(meminfo['MemTotal'])}
  8. memFree = {"memFree": 'Free memory: {0}'.format(meminfo['MemFree'])}
  9. print (memToal)
  10. print (memFree)
  11. SysInfo = {"cpu", "memToal", "memFree"}
  12. print (SysInfo)

SSH_Client

  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-
  3. from paramiko import SSHClient
  4. from paramiko import AutoAddPolicy
  5. ip = ''
  6. prot =
  7. user = ''
  8. passwd = ''
  9. cmd = 'pwd'
  10. s = SSHClient()
  11. s.set_missing_host_key_policy(AutoAddPolicy())
  12. s.connect(ip, prot, user, passwd)
  13. stdin,stdout,stderr = s.exec_command(cmd)
  14. print stdout.read()
  15. print stderr.read()
  16. s.close()