Skip to main content

AWS Resource Monitor

Small Python 3.5+ convenience library to easily monitor CPU and memory usage in AWS Batch jobs and report them to StatsD. Since it uses ECS Task Metadata V3 endpoints it is perfectly suitable to do so for other type of ECS tasks as well.

Setup

You can install this package by using pip:

pip install aws-resource-monitor

If you fancy pipenv use:

pipenv install aws-resource-monitor

To install from source, run:

python setup.py install

To install via requirements file, add the following:

-e git+https://github.com/luigisbox/aws-resource-monitor.git#egg=aws-resource-monitor

Usage

First off, you need to require the library:

from aws_resource_monitor import resource_monitoring

The resource_monitoring is a context manager accepting two positional arguments:

  • statsd_client is your own instance of StatsD client (see PythonStatsD library which will be used to report metrics.
  • metrics_prefix is a string which will prefix individual metrics.

Optionally, you can pass in keyword argument interval with timedelta object customizing polling period for new metrics (default is every five seconds).

with resource_monitoring(statsd_client, metrics_prefix):
	fn()

Behind the scenes, resource_monitoring context manager first checks for existence of ECS_CONTAINER_METADATA_URI environment variable. If it is not found, the monitor does nothing thus working well in development.

In production or when the variable exists, it creates a separate thread from your main application that reads task UUID and polls the "stats" endpoint in the metadata URI to complete and send as gauge the following metrics:

  • cpu.system
  • cpu.user
  • cpu.percent
  • memory.limit
  • memory.usage
  • memory.max_usage

A more complete example would be:

import statsd
from aws_resource_monitor import resource_monitoring

statsd = statsd.StatsClient('localhost', 8125)

with resource_monitoring(statsd, "example.metrics.", interval=timedelta(seconds=10)):
	fn()

For example, for the task UUID assigned by AWS "afc92259-3a0c-4e14-8e23-a49cc41e7947" this will report gauge "example.metrics.afc92259-3a0c-4e14-8e23-a49cc41e7947.memory.usage" and in ten seconds check and report again.

Contributing

  1. Check for open issues or open a new issue for a feature request or a bug.
  2. Fork the repository and make your changes to the master branch (or branch off of it).
  3. Send a pull request.

Development

Run the linter with:

make lint

The client library uses Black for code formatting. Code must be formatted with Black before PRs are submitted. Run the formatter with:

make fmt

Changelog

v1.0.0: 08/06/2020

Initial version.

Metadata

Release files for aws-resource-monitor 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-resource-monitor 1.0.0
File Size Uploaded Provenance Actions
aws-resource-monitor-1.0.0.tar.gz 5.0 kB Without provenance Details for aws-resource-monitor-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aws-resource-monitor 1.0.0
File Interpreter ABI Platform Actions
aws_resource_monitor-1.0.0-py3-none-any.whl Python 3 none any Details for aws_resource_monitor-1.0.0-py3-none-any.whl

Total release size: 10.2 kB

Release files / aws-resource-monitor-1.0.0.tar.gz

Download URL aws-resource-monitor-1.0.0.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d9a3a09dc15f4ed74a2cc48bb74f1a545e0a8416d3b77855550f93ba800088cf
BLAKE2b-256 checksum
How to use checksums
ce45273bd46289851b74220f32f2fd8256702e382ed2552942514788ca6817a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.16

Release files / aws_resource_monitor-1.0.0-py3-none-any.whl

Download URL aws_resource_monitor-1.0.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da22b4d90d5216d990e14ebb021a7891df2f161fef6f220ade5ebbddf6c53f1d
BLAKE2b-256 checksum
How to use checksums
1c30d45717c9ac831c79a0231e4cf02d09a4c6953cbd377a4535f22d8e53321a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.16

Security for aws-resource-monitor 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page