Added Memory monitor

This commit is contained in:
Robert Hausch 2012-04-07 17:04:36 -07:00
parent 2ec58e6d51
commit aaad5f5837
9 changed files with 40 additions and 0 deletions

View File

@ -23,6 +23,7 @@
from socket import *
from sensors.cpu import *
from sensors.memory import *
HOST = ''
PORT = 6000
@ -35,6 +36,7 @@ class Stats:
def __init__(self):
self.sensors = []
self.sensors.append(cpu_monitor())
self.sensors.append(mem_monitor())
def getStats(self):
message = ''

BIN
sensors/.cpu.py.swp Normal file

Binary file not shown.

BIN
sensors/.memory.py.swp Normal file

Binary file not shown.

0
sensors/__init__.py Normal file
View File

BIN
sensors/__init__.pyc Normal file

Binary file not shown.

20
sensors/cpu.py Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/python
import psutil
class cpu_monitor:
def __init__(self):
self.num_cpus = len(psutil.cpu_percent(0,percpu=True))
def update(self):
self.cpu_usage = psutil.cpu_percent(0.1, percpu=True)
self.cpu_times = psutil.cpu_times()
def getFormatedData(self):
message = ''
message += 'Cpu usage: '
message += ', '.join('%.1f'%x for x in self.cpu_usage)
message += ' CPU times: '
message += ', '.join('%.3f'%x for x in self.cpu_times)
return message

BIN
sensors/cpu.pyc Normal file

Binary file not shown.

18
sensors/memory.py Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/python
import psutil
class mem_monitor:
def __init__(self):
self.mem_usage = ''
self.virt_mem_usage = ''
def update(self):
self.mem_usage = psutil.phymem_usage()
self.virt_mem_usage = psutil.virtmem_usage()
def getFormatedData(self):
message = 'Memory- Phys: %.1f Virt: %.1f' % (self.mem_usage.percent, self.virt_mem_usage.percent)
return message

BIN
sensors/memory.pyc Normal file

Binary file not shown.