Statsd is a client for Etsy's node-JS statsd server.石墨堆栈收藏与石墨服务器的代理。

python-statsd的Python项目详细描述


Test StatusCoverage Status

statsd是etsy的statsd服务器的客户端,是 Graphite统计数据收集和绘图服务器。

安装

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

用法

要快速开始,请尝试以下方法:

基本用法

计时器

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

未加工

原始字符串应为预先汇总的数据或其他将 直接传给碳。这可以作为一个时间和 带宽节省机制发送大量样本可能需要 带宽(在udp报头中使用的b/w比测量器中使用的数据多,因为 实例)

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

原始类型希望有一个时间戳(从epoch开始,以秒为单位)。 标准的unix时间戳,例如“date+%s”的输出,但是如果您忽略它,或者 不提供它将提供当前时间作为消息的一部分

平均值

>>> 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的交互都将使用 指定,除非显式创建另一个Connection以使用 (如下所述)。

默认值:

  • 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
... )

如果日志记录的级别设置为调试Connection对象,则它将通知 不再发送UDP消息

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java迭代图形框架聚合达到内存限制的消息   反编译和开发人员向Android应用程序提供java安全密钥   活页夹中的java Vaadin上传组件,例如Crud编辑器   java如何定义0090当我有了每个字符   带有AOP的java截取私有注释方法   在Java中暂停并恢复动画(thread.sleep)   java在JavaFX中从不同的控制器向TableView添加行   java如何通过Spring使用脚本初始化inmemory HSQLDB   windows找到了绝对的java。通过编程从java代码获取exe路径   Java同步、信号量和队列的多线程性能   java异步任务回调未调用   java在迷宫中用坐标寻找最短路径   Java:并行处理数组,查找发生异常的位置   java我无法理解我收到的错误   如何调用。bat文件,并使用java中的ProcessBuilder发送字符串   java在mysql数据库中插入日期   将ArrayList的内容显示为格式正确的JSON for Java REST API   java@OneToMany注释SQLSyntaxErrorException:ORA000904无效标识符