mozsystemmonitor

raw JSON →
1.0.1 verified Fri May 01 auth: no python

A library to monitor system resource usage such as CPU, memory, and disk I/O. Current version is 1.0.1, with minimal recent updates.

pip install mozsystemmonitor
error AttributeError: 'SystemMonitor' object has no attribute 'measurements'
cause Accessing 'measurements' before calling 'stop()'.
fix
Call 'monitor.stop()' before accessing 'monitor.measurements'.
error ImportError: cannot import name 'SystemMonitor' from 'mozsystemmonitor'
cause Incorrect import path; the library may not be installed.
fix
Run 'pip install mozsystemmonitor' and use 'from mozsystemmonitor import SystemMonitor'.
gotcha The monitor uses a high-resolution timer but may not work correctly on virtualized environments or containers where /proc/stat is limited.
fix Ensure full /proc filesystem access (Linux) or test on actual hardware.
deprecated The 'start' method returns None; it does not return a future or handle. For async use, wrap in a thread.
fix Use threading explicitly if non-blocking behavior is required.
gotcha Disk I/O measurements may not be available on all platforms (Windows requires administrator privileges).
fix Check availability via 'monitor.available_metrics' before accessing disk data.

Start the monitor, wait 5 seconds, stop, and print the last CPU measurement.

from mozsystemmonitor import SystemMonitor
import time

monitor = SystemMonitor(1.0)  # sample interval in seconds
monitor.start()
time.sleep(5)
monitor.stop()
measurements = monitor.measurements
print(f"CPU average: {measurements.cpu_percent[-1] if measurements.cpu_percent else 'N/A'}")