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 pymetrics.recorders.base.MetricsRecorder in your application to collect and publish:

from pymetrics.recorders.default import DefaultMetricsRecorder

metrics = DefaultMetricsRecorder(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.0',
    ...
]
pymetrics~=1.0
pymetrics = {version="~=1.0"}

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-1.0.3.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

pymetrics-1.0.3-py27.py35.py36.py37.py38-none-any.whl (30.3 kB view details)

Uploaded Python 2.7 Python 3.5 Python 3.6 Python 3.7 Python 3.8

File details

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

File metadata

  • Download URL: pymetrics-1.0.3.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.7

File hashes

Hashes for pymetrics-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b7892a63f107e13793024d841c38e26be3058218b7520cf075e3ed00b7d8d98c
MD5 f8485da33485ce2b4d0e81e2b8c1262c
BLAKE2b-256 a470678bae14a2855cedf69cf9379f306d5a119f5e9d31fba4eea68a8445abca

See more details on using hashes here.

File details

Details for the file pymetrics-1.0.3-py27.py35.py36.py37.py38-none-any.whl.

File metadata

  • Download URL: pymetrics-1.0.3-py27.py35.py36.py37.py38-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.7

File hashes

Hashes for pymetrics-1.0.3-py27.py35.py36.py37.py38-none-any.whl
Algorithm Hash digest
SHA256 443ab8a518b6916393e3195a7db0261f3e702762b92c54c9291fc9a0875196c7
MD5 e2b4b80726bebd6dbe4d545b0227c1dd
BLAKE2b-256 a8b5d68ea7859de0eaf5de368ebe1a5c5c214e55720d60032a971812c474ac37

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