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.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-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyperfmon-0.2.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.tar.gz
Algorithm Hash digest
SHA256 3462921e61fe0601f0aaeca1bb36da59f5ce125f51547bcf0051ebf799156dd7
MD5 54adbcb9fd82de0bd0679adeea41d506
BLAKE2b-256 5b18d955bb0392613dcedf1a574a505bce107c0a117b5202ab0e291e2ab1a55a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyperfmon-0.2-py3-none-any.whl
  • Upload date:
  • Size: 16.7 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-py3-none-any.whl
Algorithm Hash digest
SHA256 360f19cf9ea82dc8399facc10b6d94f69d25bf265e60ddb02c00ec7980bcd5db
MD5 3e6e7d46419134271ca9672a930c2d55
BLAKE2b-256 060f6ed906bab1952204f62673839e5f171d5a81816c12e4ab525bad3409e73e

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