Versatile metrics collection for Python
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pymetrics-0.21.3.tar.gz
.
File metadata
- Download URL: pymetrics-0.21.3.tar.gz
- Upload date:
- Size: 24.4 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9e6ef46e01cb0c5d0ce38e8273cb4590e66d61a9560e69aab2089002a5fb9e3 |
|
MD5 | 3e723990869caf5059d4de931cbcba7d |
|
BLAKE2b-256 | 904d480fa42fb4296f35ba1c8911b16fc7e237a739f7d66a49b01cf4876181e5 |
File details
Details for the file pymetrics-0.21.3-py3-none-any.whl
.
File metadata
- Download URL: pymetrics-0.21.3-py3-none-any.whl
- Upload date:
- Size: 30.5 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79a44dfd0c89d1d7b6d6df04c49ffe08c2939d22d18e60a373e769da2cb3362e |
|
MD5 | e84122fee6fe31e5645d1053b047b68e |
|
BLAKE2b-256 | eb70d05d9e6a62807173c5d69bc976e9f23e521470f513aadcfbe4e71f026a67 |