Skip to main content

pyperfmon

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyperfmon-0.2.2.1.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyperfmon-0.2.2.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file pyperfmon-0.2.2.1.tar.gz.

File metadata

  • Download URL: pyperfmon-0.2.2.1.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for pyperfmon-0.2.2.1.tar.gz
Algorithm Hash digest
SHA256 a376ee0b65f181d74fad96add21db26766b54bb7e8bd21eb584bee980707aecb
MD5 3e1ae29c456969b403add0a28b45a2fc
BLAKE2b-256 27241a23dd66aef2bc7883c2e3eca77109f5c48c9444d1e6c20fb1d9ec3af9b2

See more details on using hashes here.

File details

Details for the file pyperfmon-0.2.2.1-py3-none-any.whl.

File metadata

  • Download URL: pyperfmon-0.2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for pyperfmon-0.2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d00998c05b22421d71c5898b0e245c6b37d4aff17518075d5b0fcedc69499a50
MD5 3b03545b5b33705f4bef6e49668d5a33
BLAKE2b-256 ed63dc8224db693d5b29d1466ba62e7209fb0c1d4aa7f6205f6d355c8bb09717

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page