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 18404
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(St ructure):
_fields_ = [
('dwLength', DWORD),
('dwMemoryLoad' , DWORD),
('dwTotalPhys', DWORD),
('dwAvailPhys', DWORD),
('dwTotalPageFi le', DWORD),
('dwAvailPageFi le', DWORD),
('dwTotalVirtua l', DWORD),
('dwAvailVirtua l', DWORD),
]
def winmem():
m = MEMORYSTATUS()
windll.kernel32 .GlobalMemorySt atus(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
bartonc 6,596
Recognized Expert Expert
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...
Initially I was justing looking at using Python for some event
scripting. So basically an event would trigger an object to run the
appropriate Python script, which would be run in it's entirety and
return control to the C++ code.
After looking...
|
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 one. I had an idea of
writing the IDE in C/C++, as it is a big project, bcoz of the
following
1. if python is used, then the memory required for running the IDE
will be high.
|
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 from
embedded devices). Currently, we are using a heavyweight, proprietary
log tool developed by another part of the company. This tool contains
all "standard" logging functionality, but we also need to insert
"debug" log points in the software of...
|
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 to monitor the software
does not suit our requirements.
However I am unsure how to convert dmidecode information like so :
Handle 0x0025
|
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 advance
and waiting for your reply.
|
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 following peace of code, which uses Pexpect for the same. The mentioned Poc may certainly help others, incase they need some requirement like this.
import pexpect, sys
if len(sys.argv) != 3:
print "Usage: "+sys.argv+" user new_password."
...
|
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 username and password.
Often gets "Access denied" while running the code.
I have tried to add the user to the \root\MicrosoftExchangeV2, and the
delegate control, but still cannot.
Is there anything I missing to add?
|
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 Python
for a variety of tasks. Given that the students come from a variety of
backgrounds and are not necessarily 'hackers', I'm trying to look for
examples with a bit of wow-factor.
Is there any list with people/groups/companies using Python for...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |