I want to monitor the CPU and RAM usage using Python,
Now, I know how to monitor RAM usage by Python - from ctypes import *
-
from ctypes.wintypes import *
-
-
class MEMORYSTATUS(Structure):
-
_fields_ = [
-
('dwLength', DWORD),
-
('dwMemoryLoad', DWORD),
-
('dwTotalPhys', DWORD),
-
('dwAvailPhys', DWORD),
-
('dwTotalPageFile', DWORD),
-
('dwAvailPageFile', DWORD),
-
('dwTotalVirtual', DWORD),
-
('dwAvailVirtual', DWORD),
-
]
-
def winmem():
-
m = MEMORYSTATUS()
-
windll.kernel32.GlobalMemoryStatus(byref(m))
-
return m
-
m = winmem()
-
print '%d MB physical RAM left.' % (m.dwAvailPhys/1024**2)
But I don't know how to monitor CPU realtime usage, please help me.
And how to monitor CPU and RAM used by one program?
5 18365
I want to monitor the CPU and RAM usage using Python,
Now, I know how to monitor RAM usage by Python from ctypes import *
from ctypes.wintypes import *
class MEMORYSTATUS(Structure):
_fields_ = [
('dwLength', DWORD),
('dwMemoryLoad', DWORD),
('dwTotalPhys', DWORD),
('dwAvailPhys', DWORD),
('dwTotalPageFile', DWORD),
('dwAvailPageFile', DWORD),
('dwTotalVirtual', DWORD),
('dwAvailVirtual', DWORD),
]
def winmem():
m = MEMORYSTATUS()
windll.kernel32.GlobalMemoryStatus(byref(m))
return m
m = winmem()
print '%d MB physical RAM left.' % (m.dwAvailPhys/1024**2)
But I don't know how to monitor CPU realtime usage, please help me.
And how to monitor CPU and RAM used by one program?
while i am not much into ctypes, there's another way, using WMI
check MSDN and here for more.
one example : -
>>> import wmi
-
>>> wm = wmi.WMI()
-
>>> for j in wm.Win32_PerfFormattedData_PerfOS_Memory(): print j
-
another eg: -
>>> import wmi
-
>>> wm = wmi.WMI ()
-
>>> for j in wm.Win32_Processor (): print j
-
Now I knew how to monitor CPU and Memory usage via win32pdh, while I don't know how to monitor memory usage of one application.
snippet of code: -
mempath = win32pdh.MakeCounterPath((None, "Memory", None, \
-
None, -1, "Available MBytes"))
-
query = win32pdh.OpenQuery(None, 0)
-
counter = win32pdh.AddCounter(query, mempath, 0)
-
-
win32pdh.CollectQueryData(query)
-
status, value = win32pdh.GetFormattedCounterValue(counter,
-
win32pdh.PDH_FMT_LONG)
-
These code only can monitor the whole availabe memory, I do not know how to change the CounterPath to monitor one certain application's memory usage.
anyone can help me, thanks for your reply
while i am not much into ctypes, there's another way, using WMI
check MSDN and here for more.
one example : -
>>> import wmi
-
>>> wm = wmi.WMI()
-
>>> for j in wm.Win32_PerfFormattedData_PerfOS_Memory(): print j
-
another eg: -
>>> import wmi
-
>>> wm = wmi.WMI ()
-
>>> for j in wm.Win32_Processor (): print j
-
Great link GD! Would you consider doing an article or code post for one of the sub forums. This is something that I had not heard of. Thanks for the info.
Hi,
I want to use Ctypes to monitor RAM on UNIX, what can i do ?
thanks for your help.
hicham
i think that ctypes is not supported under unix platforms. i cant found, how to get informations about memory, and i think for each platforme, it must use the apropriate command:
exp :
linux ==> use /proc/meminfo
unix ==> use for each platforme its command
i want to use one methode to get memory informations for all platforms, please if any one can help,
thanks
Sign in to post your reply or Sign up for a free account.
Similar topics
by: The_Incubator |
last post by:
As the subject suggests, I am interested in using Python as a scripting
language for a game that is primarily implemented in C++, and I am also
interested in using generators in those scripts...
...
|
by: Sridhar R |
last post by:
Hi,
I am a little experienced python programmer (2 months). I am somewhat
experienced in C/C++. I am planning (now in design stage) to write an
IDE in python. The IDE will not be a simple...
|
by: Joakim Persson |
last post by:
Hello all. I am involved in a project where we have a desire to
improve our software testing tools, and I'm in charge of looking for
solutions regarding the logging of our software (originating...
|
by: Johhny |
last post by:
Hello,
I am currently looking to write a utility in python that will monitor
the statis of a RAID card within linux. The card in Question is the LSI
SAS1064 as the tools provided by the vendor...
|
by: hacker1017 |
last post by:
im just asking out of curiosity.
|
by: dipak5801 |
last post by:
i want to know how to monitor services using SNMP protocol.
what is MIB and how can i get this information.
anyone provide me training mateiral or step by step process using snapshot .
thanks in...
|
by: geoharish |
last post by:
Dear All,
I started using Python just a few days back and there was a requirement of an assigned project to change the user Password through script without user interaction. I could write the...
|
by: garks |
last post by:
I am using Exchange 2003(Exchange Hosting), C#.
I am trying to get Mailbox usage using WMI
But I follows the coding below, still cannot get the Mailbox usage.
Even though, I predefined the...
|
by: Rajarshi |
last post by:
Hi, I teach an introductory programming course in Python. As part of
the introduction I'd like to highlight the usage of Python in
industry. The idea is to show that there are big players using...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |