[tuxdroid-svn] r5023 - software_suite_v3/software/plugin/plugin-system/trunk/plugin-system/executab
Status: Beta
Brought to you by:
ks156
|
From: jerome <c2m...@c2...> - 2009-07-03 09:48:13
|
Author: jerome
Date: 2009-07-03 11:48:05 +0200 (Fri, 03 Jul 2009)
New Revision: 5023
Modified:
software_suite_v3/software/plugin/plugin-system/trunk/plugin-system/executables/plugin-system.py
Log:
* Changed the way to retrieve cpu informations ( xp troubles with TDSS3 ).
Modified: software_suite_v3/software/plugin/plugin-system/trunk/plugin-system/executables/plugin-system.py
===================================================================
--- software_suite_v3/software/plugin/plugin-system/trunk/plugin-system/executables/plugin-system.py 2009-07-03 09:47:43 UTC (rev 5022)
+++ software_suite_v3/software/plugin/plugin-system/trunk/plugin-system/executables/plugin-system.py 2009-07-03 09:48:05 UTC (rev 5023)
@@ -26,6 +26,7 @@
from util.SimplePlugin.SimplePluginConfiguration import SimplePluginConfiguration
from util.SimplePlugin.SimplePlugin import SimplePlugin
+from win32com.client import GetObject
class Configuration(SimplePluginConfiguration):
"""
@@ -74,6 +75,12 @@
"""
This class contain utilities to retrieve system informations.
"""
+
+ def __init__(self, plug):
+ '''
+ Class initialization.
+ '''
+ self.plugin = plug
def __getPlatform(self):
'''
@@ -112,24 +119,20 @@
lo = int((usage/total)* 100)
return str(lo)
-
-
-
+
def getWindowsCPULoad(self):
'''
Return the cpu load for windows operating systems.
'''
- from win32com.client import GetObject
- wmi = GetObject('winmgmts:')
- cpu = wmi.InstancesOf('Win32_Processor')
+ result = 0
+ cmd = "WMIC CPU GET LoadPercentage "
+ response = os.popen(cmd + ' 2>&1','r').read().strip().split("\r\n")
+ for load in response[1:]:
+ result = result + (int(load))
+ return result
- x = cpu[0]
- return x.Properties_('LoadPercentage').value
-
-
-
-
-
+
+
def getLinuxMemoryUsage(self):
'''
Return the current memory usage for linux systems.
@@ -165,7 +168,7 @@
''''
Return the windows memory usage.
'''
- process = subprocess.Popen("systeminfo", stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ process = subprocess.Popen("systeminfo", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = process.stdout.read()
totalIndex = result.find("Total Physical Memory")
totalAvailable = result.find("Available Physical Memory")
@@ -213,39 +216,31 @@
if self.getCommand() == "run":
self.run(False)
elif self.getCommand() == "daemon_start":
+ self.__setDaemonRun(True)
self.runDaemon()
-
-
+
def run(self, notif):
"""
Plugin entry point for the "run" command.
"""
- cpu = "0.0"
- memory = "0.0"
+ cpu = 0
+ memory = 0
- self.throwTrace("Run 01")
- sutils = SystemUtils()
+ sutils = SystemUtils(self)
- self.throwTrace("Run 02")
if self.configuration().getCheckCpuParam():
- self.throwTrace("OK 2")
if os.name != "nt":
- self.throwTrace("LINUX")
#linux system.
cpu = sutils.getLinuxCPULoad()
if not notif:
self.throwMessage("Your c p u load is {0} percent", cpu)
else:
- self.throwTrace("WINDOWS")
#windows system.
- self.throwTrace("Get CPU")
cpu = sutils.getWindowsCPULoad()
- self.throwTrace("CPU retrieved")
if not notif:
self.throwMessage("Your c p u load is {0} percent", cpu)
-
- self.throwTrace("Run 03")
+
if self.configuration().getCheckMemParam():
if not self.isWindows():
@@ -254,17 +249,12 @@
if not notif :
self.throwMessage("Your used memory is {0} percent", memory)
else:
- self.throwTrace("Get MEMORY")
memory = sutils.getWindowsMemoryUsage()
- self.throwTrace("Memory retrieved")
if not notif :
self.throwMessage("Your used memory is {0} percent", memory)
+ self.throwTrace("hello")
+ return cpu, memory
- self.throwTrace("Run 04")
- if notif :
- return cpu, memory
-
-
def __getDaemonRun(self):
"""
"""
@@ -273,8 +263,6 @@
self.__daemonMutex.release()
return result
-
-
def __setDaemonRun(self, daemonRun):
"""
"""
@@ -282,24 +270,19 @@
self.__daemonRun = daemonRun
self.__daemonMutex.release()
-
-
def runDaemon(self):
"""
Plugin entry point for the "run_daemon" command.
"""
- self.__setDaemonRun(True)
while self.__getDaemonRun():
- self.throwTrace("Cycle step 1")
cpu, memory = self.run(True)
- self.throwTrace("Cycle step 2")
-
- if (float(cpu) > float(self.configuration().getCpuTresholdParam())):
+ self.throwTrace("datas got")
+ if (int(cpu) > int(self.configuration().getCpuTresholdParam())):
self.throwNotification("start")
self.throwMessage("c p u meltdown")
self.throwNotification("stop")
- if (float(memory) > float(self.configuration().getMemTresholdParam())):
+ if (int(memory) > int(self.configuration().getMemTresholdParam())):
self.throwNotification("start")
self.throwMessage("memory is up")
self.throwNotification("stop")
@@ -308,13 +291,13 @@
if not self.__getDaemonRun():
break
sleep(0.1)
+ sleep(3.0)
def onPluginStop(self):
"""Callback on plugin stop.
"""
self.__setDaemonRun(False)
- sys.exit(0)
def onPluginEvent(self, eventName, eventValues):
|