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 18360
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: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: 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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |