From c5134d1b21950f34cb26cd04f68ea809f171355a Mon Sep 17 00:00:00 2001 From: Robert Hausch Date: Sat, 7 Apr 2012 21:11:52 -0700 Subject: [PATCH] Minor fixes in json encoding. Increased polling speed --- monitor.py | 2 +- sensors/cpu.py | 2 +- sensors/memory.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitor.py b/monitor.py index 662de5b..94ae8e8 100755 --- a/monitor.py +++ b/monitor.py @@ -53,7 +53,7 @@ class Stats(): for s in self.sensors: s.update() self.release_write() - time.sleep(1) + time.sleep(0.1) def getStats(self): data = [] diff --git a/sensors/cpu.py b/sensors/cpu.py index c523336..cc1c865 100755 --- a/sensors/cpu.py +++ b/sensors/cpu.py @@ -13,6 +13,6 @@ class cpu_monitor: def getFormatedData(self): data = '{"name": "Usage", "values": ['+','.join('{"value": %.1f}'%x for x in self.cpu_usage)+']}' data += ',{"name": "Times", "values": [{"name": "user", "value": %.2f},{"name": "system", "value": %.2f},{"name": "idle", "value": %.2f},{"name":"nice", "value": %.2f},{"name": "iowait", "value": %.2f},{"name": "irq", "value": %.2f},{"name": "softirq", "value": %.2f}]}' % (self.cpu_times.user, self.cpu_times.system, self.cpu_times.idle, self.cpu_times.nice, self.cpu_times.iowait, self.cpu_times.irq, self.cpu_times.softirq) - message = '{"type": "Cpu", "value": "%.1f", "data": [%s]}' % ( sum(self.cpu_usage)/self.num_cpus, data ) + message = '{"type": "Cpu", "value": %.1f, "data": [%s]}' % ( sum(self.cpu_usage)/self.num_cpus, data ) return message diff --git a/sensors/memory.py b/sensors/memory.py index 6b9fbbf..44bf4e1 100644 --- a/sensors/memory.py +++ b/sensors/memory.py @@ -12,7 +12,7 @@ class mem_monitor: self.virt_mem_usage = psutil.virtmem_usage() def getFormatedData(self): - message = '{"type": "Memory", "value": "%.1f", "data": [{"name": "Physical", "value": "%.1f"},{"name": "Virtual", "value": "%.1f"}]}' % (self.mem_usage.percent, self.mem_usage.percent, self.virt_mem_usage.percent) + message = '{"type": "Memory", "value": %.1f, "data": [{"name": "Physical", "value": "%.1f"},{"name": "Virtual", "value": "%.1f"}]}' % (self.mem_usage.percent, self.mem_usage.percent, self.virt_mem_usage.percent) return message