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.

For an alternative implementation of the same concept, but less tied to the Python ecosystem, see resource-tracker-rs.

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.

It also supports streaming resource usage data to a remote location for central analysis, visualization, and recommendations. To get started, visit the sentinel.sparecores.com website to register a free account, generate an API key, and use it to configure the resource-tracker package via the SENTINEL_API_KEY environment variable. Find more details in the the streaming 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
  • 3.14

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.5.0.tar.gz (257.0 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.5.0-py3-none-any.whl (273.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for resource_tracker-0.5.0.tar.gz
Algorithm Hash digest
SHA256 c90366b6644444e090fc2776f8c423a8de1589169beda5d5f6187c648c081e3a
MD5 1f450af2cb20eea7ff239d0112115a4f
BLAKE2b-256 c49cb9ecccae6294dc48cecebc06775555e69d61c0510669588ab1dc72bb7cc2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for resource_tracker-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9dd9cb3eeaa0b4630e11685fa7913e02f53533aebc193b8f59509d9cd112f12e
MD5 3cbb5ee3a140b2faadf0a4447253ab4c
BLAKE2b-256 e76c7c6da71b805852085c819e7edf91caa50a9700b640f5e43fc4c9bcf5416d

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