Skip to main content

Versatile metrics collection for Python

Project description

https://readthedocs.org/projects/pymetrics/badge/ https://pepy.tech/badge/pymetrics https://img.shields.io/pypi/l/pymetrics.svg https://api.travis-ci.org/eventbrite/pymetrics.svg https://img.shields.io/pypi/v/pymetrics.svg https://img.shields.io/pypi/wheel/pymetrics.svg https://img.shields.io/pypi/pyversions/pymetrics.svg

PyMetrics is versatile metrics collection library for Python that encapsulates the collection of counters, gauges, histograms, and timers into a generic interface with pluggable publishers so that you can helpfully instrument your applications without suffering vendor lock.


Publishing metrics is a straightforward process involving two steps. First, configure your metrics and publisher(s):

METRICS_CONFIG = {
    'version': 2,
    'error_logger_name': 'pymetrics',
    'publishers': [
        {
            'path': 'pymetrics.publishers.datadog.DogStatsdPublisher',
            'kwargs': {
                'host': 'localhost',
                'port': 8135,
            },
        },
    ],
}

Then, use a MetricsRecorder in your application to collect and publish:

from pymetrics.recorder import DefaultMetricsRecorder

metrics = MetricsRecorder(config=settings.METRICS_CONFIG)

metrics.counter('counter.name').increment()

metrics.gauge('gauge.name', tag_name1='tag_value1', tag_name2='tag_value2').set(12)

metrics.histogram('histogram.name').set(1730)

with metrics.timer('timer.name'):
    do_something()

cumulative_timer = metrics.timer('cumulative_timer.name')
for item in items:
    do_something_without_timing()
    with cumulative_timer:
        do_something_with_timing()

metrics.publish_all()

Provided publisher plugins include Statsd, Datadog, Python Logging, SQLite, and a null publisher. Writing your own is simple and we encourage you to share your work with the community by submitting a pull request.

License

PyMetrics is licensed under the Apache License, version 2.0.

Installation

PyMetrics is available in PyPi and can be installing directly via Pip or listed in setup.py, requirements.txt, or Pipfile:

pip install 'pymetrics~=1.0'
install_requires=[
    ...
    'pymetrics~=1.26',
    ...
]
pymetrics~=1.26
pymetrics = {version="~=1.26"}

Documentation

The complete PyMetrics documentation is available on Read the Docs!

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

pymetrics-0.21.0.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

pymetrics-0.21.0-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

Details for the file pymetrics-0.21.0.tar.gz.

File metadata

  • Download URL: pymetrics-0.21.0.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.7

File hashes

Hashes for pymetrics-0.21.0.tar.gz
Algorithm Hash digest
SHA256 f584c0e30aa80344a8d9a2fb02e62421eb691db7645e3f84e2fb283269eff58d
MD5 7f14134e37dc32f6053ff5def067d823
BLAKE2b-256 dd9f023adeb50420faaa8cf82605c3941477134bc7d36d66939b39b67f5ffd86

See more details on using hashes here.

File details

Details for the file pymetrics-0.21.0-py3-none-any.whl.

File metadata

  • Download URL: pymetrics-0.21.0-py3-none-any.whl
  • Upload date:
  • Size: 30.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.7

File hashes

Hashes for pymetrics-0.21.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df488c77fc61d1973a338b392bd478d28bc8db288a8505092ae7089edf5e64a2
MD5 31ed0e49592017478026321fab4073e6
BLAKE2b-256 13c89a4db35883a6b516a04c2b7b6e42d7c34ff90b7859cc10a9651cc5ef9ab2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page