Author: jerome
Date: 2009-03-14 16:20:20 +0100 (Sat, 14 Mar 2009)
New Revision: 4074
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/tuxdroid-gadget-system.py
Log:
* the gadget now take the used memory average on windows.
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/tuxdroid-gadget-system.py
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/tuxdroid-gadget-system.py
2009-03-14 14:21:39 UTC (rev 4073)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/tuxdroid-gadget-system.py
2009-03-14 15:20:20 UTC (rev 4074)
@@ -25,6 +25,7 @@
import commands
import os
import platform
+import subprocess
import string
from time import sleep
@@ -78,28 +79,39 @@
'''
if self.tgp_giveCPU :
- cpu = self.__getCPULoad()
-
- if self.tgp_useCpuThreshold:
- #check threshold.
- if (float(cpu) > float(self.tgp_cpuThreshold)):
- print("message \"c p u meltdown\"")
- else:
- print("message \"Your c p u load is over\"")
- print("message \"" + str(cpu) + "%\"")
+ if not self.isWindows():
+ #linux system.
+ cpu = self.__getLinuxCPULoad()
+
+ if self.tgp_useCpuThreshold:
+ #check threshold.
+ if (float(cpu) > float(self.tgp_cpuThreshold)):
+ print("message \"c p u meltdown\"")
+ else:
+ print("message \"Your c p u load is over\"")
+ print("message \"" + str(cpu) + "%\"")
+ else:
+ #windows system.
+ #TODO
+ pass
if self.tgp_giveMem:
- memory = self.__getMemoryUsage()
+ if not self.isWindows():
+ #linux system.
+ memory = self.__getLinuxMemoryUsage()
+ else:
+ memory = self.__getWindowsMemoryUsage()
+
+ if self.tgp_useMemThreshold:
+ if (float(memory) > float(self.tgp_memThreshold)):
+ print("message \"memory is up\"")
+ else:
+ print("message \"Your used memory is over\"")
+ print("message \"" + str(memory) + "%\"")
- if self.tgp_useMemThreshold:
- if (float(memory) > float(self.tgp_memThreshold)):
- print("message \"memory is up\"")
- else:
- print("message \"Your used memory is over\"")
- print("message \"" + str(memory) + "%\"")
-
+
@@ -122,36 +134,41 @@
- def __getCPULoad(self):
+ def __getLinuxCPULoad(self):
'''
- Return the current cpu load.
+ Return the current cpu load for linux systems.
'''
- if not self.isWindows():
- data = commands.getoutput("cat /proc/stat")
- u1 = float( data.split()[1] )
- n1 = float( data.split()[2] )
- s1 = float( data.split()[3] )
- i1 = float( data.split()[4] )
- sleep(2)
- datas = commands.getoutput("cat /proc/stat")
- u2 = float( datas.split()[1] )
- n2 = float( datas.split()[2] )
- s2 = float( datas.split()[3] )
- i2 = float( datas.split()[4] )
- usage = (u2-u1) + (n2 - n1) + (s2 - s1)
- total = (u2-u1) + (n2 - n1) + (s2 - s1) + (i2 -i1)
- lo = (usage/total)* 100
- return lo
-
- else:
- return 'todo'
+ data = commands.getoutput("cat /proc/stat")
+ u1 = float( data.split()[1] )
+ n1 = float( data.split()[2] )
+ s1 = float( data.split()[3] )
+ i1 = float( data.split()[4] )
+ sleep(2)
+ datas = commands.getoutput("cat /proc/stat")
+ u2 = float( datas.split()[1] )
+ n2 = float( datas.split()[2] )
+ s2 = float( datas.split()[3] )
+ i2 = float( datas.split()[4] )
+ usage = (u2-u1) + (n2 - n1) + (s2 - s1)
+ total = (u2-u1) + (n2 - n1) + (s2 - s1) + (i2 -i1)
+ lo = (usage/total)* 100
+ return lo
+
+
+
+
+ def __getWindowsCPULoad(self):
+ '''
+ Return the cpu load for windows operating systems.
+ '''
+ pass
- def __getMemoryUsage(self):
+ def __getLinuxMemoryUsage(self):
'''
- Return the current memory usage.
+ Return the current memory usage for linux systems.
'''
def get_freemem():
"""
@@ -173,15 +190,29 @@
free = commands.getoutput("""cat /proc/meminfo | grep MemFree |
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
return str(int(total)/1024 - int(cached.split()[0])/1024 -
int(buffers)/1024 - int(free)/1024)
+ free = get_freemem()
+ used = get_usedmem()
+
+ return str(float((float(used) / (float(used) + float(free))) * 100.0))
+
+
+
+ def __getWindowsMemoryUsage(self):
+ ''''
+ Return the windows memory usage.
+ '''
+ cmd = ["systeminfo", "|", "find", "\"Available Physical Memory\""]
+ process = subprocess.Popen("systeminfo", stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
+ result = process.stdout.read()
+ totalIndex = result.find("Total Physical Memory")
+ totalAvailable = result.find("Available Physical Memory")
+ totalMem = result.find("MB", totalIndex, totalAvailable)
+ totalMem = result[ totalIndex + len("Total Physical Memory:") :
totalMem ]
+ freeMem = result.find("MB", totalAvailable)
+ freeMem = result[ totalAvailable + len("Available Physical Memory:") :
freeMem ]
+ totalMem = string.replace(totalMem.strip(), ".", "")
+ freeMem = string.replace(freeMem.strip(), ".", "")
+ return str(float( float(int(totalMem) - int(freeMem)) /
float(totalMem) ) * 100)
- if not self.isWindows():
- free = get_freemem()
- used = get_usedmem()
- return str(float((float(used) / (float(used) + float(free))) *
100.0))
-
- else:
- return "todo"
-
-
tuxdroid_gadget_pcMonitor = pcMonitor()
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn