Skip to main content

Lightweight Python package for monitoring process and system resource usage with optional Metaflow integration for cloud cost optimization.

Project description

resource-tracker

A lightweight, zero-dependency Python package for monitoring resource usage across processes and at the system level. Designed with batch jobs in mind (like Python or R scripts, or Metaflow steps), it provides simple tools to track CPU, memory, GPU, network, and disk utilization with minimal setup -- e.g. using a step decorator in Metaflow to automatically track resource usage and generate a card with data visualizations on historical resource usage and cloud server recommendations for future runs.

Installation

You can install the stable version of the package from PyPI: resource-tracker on PyPI

pip install resource-tracker

Development version can be installed directly from the git repository:

pip install git+https://github.com/sparecores/resource-tracker.git

Note that depending on your operating system, you might need to also install psutil (e.g. on MacOS and Windows). For more details, see the OS support section.

Integrations

The resource-tracker Python package is designed to be used in a variety of ways, even outside of Python. Find more details about how to use it directly from Python, R, or via our framework integrations, such as Metaflow, in the integrations section of the documentation.

Operating System Support

The package was originally created to work on Linux systems (as the most commonly used operating system on cloud servers) using procfs directly and without requiring any further Python dependencies, but to support other operating systems as well, now it can also use psutil when available.

To make sure the resource tracker works on non-Linux systems, install via:

pip install resource-tracker[psutil]

Minor inconsistencies between operating systems are expected, e.g. using PSS (Proportional Set Size) instead of RSS (Resident Set Size) as the process-level memory usage metric on Linux, as it is evenly divides the shared memory usage between the processes using it, making it more representative of the memory usage of the monitored applications. Mac OS X and Windows use USS (Unique Set Size) instead.

CI/CD is set up to run tests on the below operating systems:

  • Ubuntu latest LTS (24.04)
  • MacOS latest (13)
  • Windows latest (Windows Server 2022)

Unit tests status for each operating system

Python Version Support

The package supports Python 3.9 and above.

CI/CD is set up to run tests on the below Python versions on Ubuntu latest LTS, Windows Server 2022 and MacOS latest:

  • 3.9
  • 3.10
  • 3.11
  • 3.12
  • 3.13

Unit tests status per Python version

Performance

The performance of the procfs and the psutil implementations is similar, see e.g. benchmark.py for a comparison of the two implementations when looking at process-level stats:

PSUtil implementation: 0.082130s avg (min: 0.067612s, max: 0.114606s)
ProcFS implementation: 0.084533s avg (min: 0.081533s, max: 0.111782s)
Speedup factor: 0.97x (psutil faster)

On a heavy application with many descendants (such as Google Chrome with hundreds of processes and open tabs):

PSUtil implementation: 0.201849s avg (min: 0.193392s, max: 0.214061s)
ProcFS implementation: 0.182557s avg (min: 0.174610s, max: 0.192760s)
Speedup factor: 1.11x (procfs faster)

The system-level stats are much cheaper to collect, and there is no effective difference in performance between the two implementations.

Why have both implementations then? The psutil implementation works on all operating systems at the cost of the extra dependency, while the procfs implementation works without any additional dependencies, but only on Linux. This latter can be useful when deploying cloud applications in limited environments without easy control over the dependencies (e.g. Metaflow step decorator without explicit @pypi config).

References

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

resource_tracker-0.4.1.tar.gz (212.2 kB view details)

Uploaded Source

Built Distribution

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

resource_tracker-0.4.1-py3-none-any.whl (234.6 kB view details)

Uploaded Python 3

File details

Details for the file resource_tracker-0.4.1.tar.gz.

File metadata

  • Download URL: resource_tracker-0.4.1.tar.gz
  • Upload date:
  • Size: 212.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for resource_tracker-0.4.1.tar.gz
Algorithm Hash digest
SHA256 126651547df82d56f08a9af36e1e7c1a27c6bb2adcff112d29abc3570579c242
MD5 0bf16818f172ecffcf02058e3cabf296
BLAKE2b-256 5f0eb8552ba3e06d8857860996ed7fbe1cd88908ab8e594024274268fd2d2259

See more details on using hashes here.

File details

Details for the file resource_tracker-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for resource_tracker-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d28760f4a4228889bd35d615fe8e8f34d1ee4d9ab2a0bf5eff772ed31e0399f6
MD5 b6c58a6d5896cb6dcaa3b2d6e2403cd4
BLAKE2b-256 2f8cec1d949ea676fc84ab8de3d148e9d5c040fde7259f50584bb0199fd809be

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