跳转到主要内容

statsd 是 Etsy 的 node-js statsd 服务器客户端。Graphite 统计收集和绘图服务器的代理。

项目描述

Test Status Coverage Status

statsd 是 Etsy 的 statsd 服务器客户端,是 Graphite 统计收集和绘图服务器的客户端/代理。

安装

要安装,只需执行 python setup.py install。如果您想先运行测试,请运行 python setup.py nosetests

用法

要快速开始,只需尝试以下内容

基本用法

计时器

>>> import statsd
>>>
>>> timer = statsd.Timer('MyApplication')
>>>
>>> timer.start()
>>> # do something here
>>> timer.stop('SomeTimer')

计数器

>>> import statsd
>>>
>>> counter = statsd.Counter('MyApplication')
>>> # do something here
>>> counter += 1

仪表

>>> import statsd
>>>
>>> gauge = statsd.Gauge('MyApplication')
>>> # do something here
>>> gauge.send('SomeName', value)

原始数据

原始字符串应该是例如预先汇总的数据或其他将直接传递给 carbon 的数据。这可以用作节省时间和带宽的机制,发送大量样本可能会使用大量带宽(例如,比仪表数据使用的 UDP 报头中的带宽更多)。

>>> import statsd
>>>
>>> raw = statsd.Raw('MyApplication', connection)
>>> # do something here
>>> raw.send('SomeName', value, timestamp)

原始类型需要自纪元以来(标准 Unix 时间戳,例如“date +%s”的输出)的秒数作为时间戳,但如果您省略它或提供 None,它将作为消息的一部分提供当前时间

平均值

>>> import statsd
>>>
>>> average = statsd.Average('MyApplication', connection)
>>> # do something here
>>> average.send('SomeName', 'somekey:%d'.format(value))

连接设置

如果您需要除默认之外的其他设置 Connection,您可以使用 Connection.set_defaults()

>>> import statsd
>>> statsd.Connection.set_defaults(host='localhost', port=8125, sample_rate=1, disabled=False)

设置这些配置后,与statsd的每次交互都将使用您指定的配置,除非您明确创建不同的连接来使用(下面将描述)。

默认值

  • host = 'localhost'

  • port = 8125

  • sample_rate = 1

  • disabled = False

高级用法

>>> import statsd
>>>
>>> # Open a connection to `server` on port `1234` with a `50%` sample rate
>>> statsd_connection = statsd.Connection(
...     host='server',
...     port=1234,
...     sample_rate=0.5,
... )
>>>
>>> # Create a client for this application
>>> statsd_client = statsd.Client(__name__, statsd_connection)
>>>
>>> class SomeClass(object):
...     def __init__(self):
...         # Create a client specific for this class
...         self.statsd_client = statsd_client.get_client(
...             self.__class__.__name__)
...
...     def do_something(self):
...         # Create a `timer` client
...         timer = self.statsd_client.get_client(class_=statsd.Timer)
...
...         # start the measurement
...         timer.start()
...
...         # do something
...         timer.intermediate('intermediate_value')
...
...         # do something else
...         timer.stop('total')

如果需要关闭服务并避免发送UDP消息,可以通过启用disabled参数来禁用Connection类

>>> statsd_connection = statsd.Connection(
...     host='server',
...     port=1234,
...     sample_rate=0.5,
...     disabled=True
... )

如果将日志级别设置为debug,Connection对象将通知它不再发送UDP消息。

项目详情


下载文件

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

源分布

python-statsd-2.1.0.tar.gz (10.8 kB 查看哈希值)

上传时间

构建分布

python_statsd-2.1.0-py2.py3-none-any.whl (14.5 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面