statsd 是 Etsy 的 node-js statsd 服务器客户端。Graphite 统计收集和绘图服务器的代理。
项目描述
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的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d2c573d325d0f015b4d79f0d0f8c88dd8413d7b9ef890c09076a9b6089ab301c |
|
MD5 | 899b5a64d31abd8304660432503a04c3 |
|
BLAKE2b-256 | bcea0beeadf66faed4ccdcb48009bb4eebf580ac6c05e55b6fae4032c6c45b9a |
关闭
python_statsd-2.1.0-py2.py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f0b8b3333a7d474a3b0ece069e4849febdc66d2712d5290aea6ff1189a05fb80 |
|
MD5 | 3586ccc9e53371907bbeac6853d7db5d |
|
BLAKE2b-256 | 6faf224e67da2deda72317aa9afe3445cf849ebd86f4001e20b5d164ef9d05f8 |