Skip to main content

pyperfmon

Latest PyPI version Number of PyPI downloads

Python Module for reading performance monitor counters from local and remote windows machines

This module is designed to make querying performance monitor counters in python easy for both local and remote machines.

There is only one dependancy, the WMI module that is used to connect to the machine to be monitored and query the counters.

Only one instance needs to be created and can be used to connect to many machines, even when using different credentials for each machine.

Using this module

First import the module and create an instance

from pyperfmon import pyperfmon

pm = pyperfmon.pyperfmon()

Connecting

If the windows domain account you are running this code with, has sufficient privileges to connect to and view performance monitor counters on the remote machine that you want to monitor, then calling connect is optional, it will be triggered automatically when you call another function. However it may be advantageous to call the connect function to improve the performance of your code when retrieving the first counter.

pm.connect("hostname")

If you need different credentials to connect to another machine then you you will need to call connect with that user account, using the optional username and password arguments, this is not optional as this is the only way you can provide a different user account when connecting. e.g:

pm.connect("server1", r"domain\user1", "password1")
pm.connect("server2", "domain\\user1", "password1")
pm.connect("server3.dns.siffix", "localuser", "password2")
pm.connect("192.168.1.13", r"domain2\user13", "password13")

Querying performance monitor counters

Querying performance monitor counters is done with the getCounter function, which takes 1 or 2 arguments, the first argument, the performance counter is mandatory, the second is the hostname you want to read the counter from. If the optional hostname argument is not used the counter will be read from the localhost.

There are 2 options when specifying the counter, the first is the single instance counters where you specify "Object\counter name" e.g.

print(pm.getCounter(r"Memory\Pages/sec"))

The second is the multi-instance counters where you specify "Object\instance\counter name" e.g.

print(pm.getCounter(r"Processor\0\% Processor Time"))
print(pm.getCounter(r"Processor\1\% Processor Time"))
print(pm.getCounter(r"Processor\2\% Processor Time"))
print(pm.getCounter(r"Processor\3\% Processor Time"))
print(pm.getCounter(r"Processor\_Total\% Processor Time"))

The same examples from when monitoring multiple hosts

print(pm.getCounter(r"Memory\Pages/sec", "server1"))
print(pm.getCounter(r"Processor\0\% Processor Time", "server1"))
print(pm.getCounter(r"Processor\1\% Processor Time", "server1"))
print(pm.getCounter(r"Processor\2\% Processor Time", "server1"))
print(pm.getCounter(r"Processor\3\% Processor Time", "server1"))
print(pm.getCounter(r"Processor\_Total\% Processor Time", "server1"))

print(pm.getCounter(r"Memory\Pages/sec", "server2"))
print(pm.getCounter(r"Processor\0\% Processor Time", "server2"))
print(pm.getCounter(r"Processor\1\% Processor Time", "server2"))
print(pm.getCounter(r"Processor\2\% Processor Time", "server2"))
print(pm.getCounter(r"Processor\3\% Processor Time", "server2"))
print(pm.getCounter(r"Processor\_Total\% Processor Time", "server2"))

Querying available performance monitor counters

As the performance monitor counters names are localised and you may not know the localised name used on the server you want to monitor or you may want to check first if the counters you are interested is available on the remote machine. for this we provide these 2 utility function

  • getCounterObjects - returns a list of objects on windows machine being monitored. e.g.
print(pm.getCounterObjects("server1"))
  • getCounters - returns a list of counters available for a specific object on the windows machine being monitored. e.g.
print(pm.getCounters("System", "server1"))

Again with these functions the hostname is optional, if omitted the localhost will be queried.

Installing

pip install pyperfmons

Metadata

Release files for pyperfmon 0.2.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyperfmon 0.2.2.1
File Size Uploaded
pyperfmon-0.2.2.1.tar.gz 16.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyperfmon 0.2.2.1
File Interpreter ABI Platform
pyperfmon-0.2.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 33.0 kB

Release files / pyperfmon-0.2.2.1.tar.gz

Download URL pyperfmon-0.2.2.1.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a376ee0b65f181d74fad96add21db26766b54bb7e8bd21eb584bee980707aecb
BLAKE2b-256 checksum
How to use checksums
27241a23dd66aef2bc7883c2e3eca77109f5c48c9444d1e6c20fb1d9ec3af9b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / pyperfmon-0.2.2.1-py3-none-any.whl

Download URL pyperfmon-0.2.2.1-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d00998c05b22421d71c5898b0e245c6b37d4aff17518075d5b0fcedc69499a50
BLAKE2b-256 checksum
How to use checksums
ed63dc8224db693d5b29d1466ba62e7209fb0c1d4aa7f6205f6d355c8bb09717
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.2.2.1 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page