跳转到主要内容

Python的多功能指标收集库

项目描述

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 是一个多功能的Python指标收集库,它将计数器、仪表、直方图和计时器封装到一个通用接口中,并具有可插拔的发布者,以便您可以在不遭受供应商锁定的情况下帮助性地监控应用程序。


发布指标是一个简单的两个步骤的过程。首先,配置您的指标和发布者

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

然后,在您的应用程序中使用 pymetrics.recorders.base.MetricsRecorder 来收集和发布

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()

提供的发布者插件包括Statsd、Datadog、Python日志记录、SQLite和null发布者。编写自己的插件很简单,我们鼓励您通过提交拉取请求的方式与社区分享您的工作。

许可证

PyMetrics遵循Apache许可证,版本2.0

安装

PyMetrics可在PyPI上找到,可以通过Pip直接安装,或在setup.pyrequirements.txtPipfile中列出。

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

文档

PyMetrics的完整文档可在Read the Docs上找到!

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

pymetrics-1.0.10.tar.gz (24.0 kB 查看哈希值)

上传时间

构建分布

pymetrics-1.0.10-py27.py35.py36.py37.py38-none-any.whl (30.3 kB 查看哈希值)

上传时间 Python 2.7 Python 3.5 Python 3.6 Python 3.7 Python 3.8

由以下支持