使用statsd的金字塔性能度量

pyramid_metrics的Python项目详细描述


使用statsd的金字塔的性能度量。该项目旨在提供 以最少侵入的方式插入金字塔应用程序的方法。

安装

使用setuptools安装,例如(在virtualenv中):

$ pip install pyramid_metrics

设置

安装pyramid_metrics后,必须使用config.include 将其包含到金字塔项目配置中的机制。在你的 金字塔项目的__init__.py

config=Configurator(.....)config.include('pyramid_metrics')

或者,您可以在 .ini文件:

[app:myapp]pyramid.includes=pyramid_metrics

用法

金字塔度量配置(默认值):

[app:myapp]metrics.host=localhostmetrics.port=8125metrics.prefix=application.stagemetrics.route_performance=true

路线性能

如果启用,路由性能功能将计时请求处理。 通过使用statsd计时器类型度量,预聚合将提供信息 关于延迟、速率和总数。信息发送两次:每条路线 在全球范围内。

密钥名由路由名组成, http方法和结果(作为http状态代码或“exc”表示异常)。

  • 全局键request.<HTTP_METHOD>.<STATUS_CODE_OR_EXC>
  • 每个路由密钥route.<ROUTE_NAME>.request.<HTTP_METHOD>.<STATUS_CODE_OR_EXC>

API

计数器

STATSD类型: https://github.com/etsy/statsd/blob/master/docs/metric_types.md#counting

# Increment a counter named cache.hit by 1request.metrics.incr('cache.hit')# Increment by Nrequest.metrics.incr(('cache.hit.read.total',count=len(cacheresult)))# Stat names can be composed from list or tuplerequest.metrics.incr(('cache',cache_action))

仪表

STATSD类型: https://github.com/etsy/statsd/blob/master/docs/metric_types.md#gauges

# Set the number of SQL connections to 8request.metrics.gauge('sql.connections',8)# Increase the value of the metrics by some amountrequest.metrics.gauge('network.egress',34118,delta=True)

计时器

STATSD类型: https://github.com/etsy/statsd/blob/master/docs/metric_types.md#timing

# Simple timingtime_in_ms=requests.get('http://example.net').elapsed.microseconds/1000request.metrics.timing('net.example.responsetime',time_in_ms)# Using the time marker mechanismrequest.metrics.marker_start('something_slow')httpclient.get('http://example.net')request.metrics.marker_stop('something_slow')# Measure different outcomerequest.metrics.marker_start('something_slow')try:httpclient.get('http://example.net').raise_for_status()except:# Send measure to key 'something_slow.error'request.metrics.marker_stop('something_slow',suffix='error')else:# Send measure to key 'something_slow.ok'request.metrics.marker_stop('something_slow',suffix='ok')# Using the context managerwithrequest.metrics.timer(['longprocess',processname]):run_longprocess(processname)# Send measure to 'longprocess.foobar' or 'longprocess.foobar.exc'

当前实施

  • 收集实用程序作为请求方法
  • 能够按金字塔路由发送度量值
  • 简单的时间标记机制
  • 简单计数器
  • 计时度量类型的上下文管理器

待办事项

  • 全statsd度量类型
  • 自动计量扩展(sqlalchemy、mongodb、requests…)
  • 白名单/指标黑名单
  • 每个子系统的时间分配(使用时间标记机制)

注意事项

  • 一般错误策略是:总是故障保护。金字塔度量永远不应该 打破你的申请。
  • DNS解析是在配置期间完成的,以避免重复的延迟。

开发

运行测试

测试由nose运行,所有依赖项都在requirements-test.txt中。

$ pip install -r requirements-test
...

$ nosetests
...

进行毒性

$ pip install tox
...

$ tox          # Run on python 2.7 and python 3.4
...

$ tox -e py34  # Run on python 3.4 only

贡献者

  • 皮奥巴斯蒂达(@pior)
  • 菲利普·高希尔(@deuxpi)
  • 哈德里安·大卫(@hadrien)
  • 杰·R·雷恩(@jrrren)

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

推荐PyPI第三方库


热门话题
在java中使用鼠标在画布上绘制线而不使用Swing   java如何调试库代码中发生的NullPointerException?   java GWT在发送前在JSON中序列化POST参数   java如何在失去internet连接时停止脚本执行,并在重新连接internet时重新恢复?   尝试通过上下文菜单更新适配器时引发java Null异常   如果不更改Jersey路径,java执行器端点将无法工作   java Spring AuthenticationManager是否将有效令牌保存在内存中的某个位置?   java游戏!2.0应用程序启动时数据库覆盖。(MYSQL)   java使用spring表达式语言计算二维数组中的单元格   java为什么在这个Spring应用程序中使用JdbcTemplate BeanPropertyRowMapper类时获得这个实例化异常?   在Java中使用自定义JMXAuthenticator以编程方式从客户端远程连接到JMX的身份验证   hibernate JBoss+Java:尝试使用其他模块会话对象时出现事务未激活错误   java在JavaFX setOnAction()方法中写入OutputStream   java Spring AWS上下文凭据不工作   将@index添加到字段后,java Objectify筛选器不起作用   java我在Mac上安装了java6和java8,我使用的是哪一种?   java下面这两种语言的区别是什么?