3

I am using the following code to get remote PC CPU percentage of usage witch is slow and loading the remote PC because of SSHing.

per=(subprocess.check_output('ssh root@192.168.32.218 nohup python psutilexe.py',stdin=None,stderr=subprocess.STDOUT,shell=True)).split(' ')
print 'CPU %=',float(per[0])
print 'MEM %=',float(per[1])

where psutilexe.py is as follows:

import psutil
print psutil.cpu_percent(), psutil.virtual_memory()[2]

Would you please let me know if there is any alternate way to measure remote PC CPU % of usage using Python?

julienc
  • 19,087
  • 17
  • 82
  • 82
Sarath M
  • 46
  • 1
  • 3
  • you can do this by enabling SNMP on your host and read CPU/RAM informations using pysnmp on your remote host – alone Aug 08 '16 at 10:39

3 Answers3

1

I would suggest taking look at Glances. It's written in python and can also be used for remote server monitoring:

https://github.com/nicolargo/glances

Using glances on remote server:

http://mylinuxbook.com/glances-an-all-in-one-system-monitoring-tool/

Maxo
  • 528
  • 4
  • 13
0

You don't need a custom Python script, since you can have CPU usage directly with top, (or with sysstat, if installed).

Have you profiled your app? Is it the custom script which is making it slow, or the SSHing itself? If it's the SSHing, then:

  • Consider logging once if you're getting multiple values, or:

  • Consider using message queue instead of SSHing: monitored machines will constantly send their CPU usage to a message queue service, which will be listened by the machine which is in charge of gathering the results.

Community
  • 1
  • 1
Arseni Mourzenko
  • 50,338
  • 35
  • 112
  • 199
0

I had been looking for it for a while and I think WMI does what you need.

WMI_Python_Documentation

import wmi
pc = wmi.WMI('PC_Name')
cpu = pc.Win32_Processor()
for i in cpu:
    print (i.LoadPercentage)

Hopefully this is what you need.

julio
  • 121
  • 1
  • 4