记录您的应用程序的性能指标
项目描述
使用相同的 API 调整 StatsD 中的计数器和计时器指标。
配置是通过使用特定混入定义的键通过 tornado.web.Application 设置属性来完成的。
文档
Statsd 混入
以下代码片段配置了来自常见环境变量的 StatsD 混入。此简单处理程序将发出计时器指标,以标识对 get 方法的每次调用,以及针对数据库查询的单独指标。
import os
from sprockets.mixins import mediatype
from sprockets.mixins.metrics import statsd
from tornado import web
import queries
def make_application():
application = web.Application([
web.url(r'/', MyHandler),
], **settings)
statsd.install({'namespace': 'my-application',
'host': os.environ.get('STATSD_HOST', '127.0.0.1'),
'port': os.environ.get('STATSD_PORT', '8125')})
return application
class MyHandler(statsd.StatsdMixin,
mediatype.ContentMixin,
web.RequestHandler):
def initialize(self):
super(MyHandler, self).initialize()
self.db = queries.TornadoSession(os.environ['MY_PGSQL_DSN'])
async def get(self, obj_id):
with self.execution_timer('dbquery', 'get'):
result = await self.db.query('SELECT * FROM foo WHERE id=%s',
obj_id)
self.send_response(result)
设置
- namespace:
度量的命名空间
- host:
Statsd 主机
- port:
Statsd 端口
- prepend_metric_type:
可选标志,用于将桶路径与 StatsD 指标类型连接在一起
开发快速入门
$ python3.4 -mvenv env
$ . ./env/bin/activate
(env)$ env/bin/pip install -r requires/development.txt
(env)$ nosetests
test_metrics_with_buffer_not_flush (tests.InfluxDbTests) ... ok
test_that_cached_db_connection_is_used (tests.InfluxDbTests) ... ok
test_that_counter_is_tracked (tests.InfluxDbTests) ... ok
test_that_execution_timer_is_tracked (tests.InfluxDbTests) ... ok
test_that_http_method_call_details_are_recorded (tests.InfluxDbTests) ... ok
test_that_metric_tag_is_tracked (tests.InfluxDbTests) ... ok
test_that_add_metric_tag_is_ignored (tests.StatsdMethodTimingTests) ... ok
test_that_cached_socket_is_used (tests.StatsdMethodTimingTests) ... ok
test_that_counter_accepts_increment_value (tests.StatsdMethodTimingTests) ... ok
test_that_counter_increment_defaults_to_one (tests.StatsdMethodTimingTests) ... ok
test_that_default_prefix_is_stored (tests.StatsdMethodTimingTests) ... ok
test_that_execution_timer_records_time_spent (tests.StatsdMethodTimingTests) ... ok
test_that_http_method_call_is_recorded (tests.StatsdMethodTimingTests) ... ok
----------------------------------------------------------------------
Ran 13 tests in 3.572s
OK
(env)$ ./setup.py build_sphinx -q
running build_sphinx
(env)$ open build/sphinx/html/index.html
项目详情
关闭
sprockets.mixins.metrics-4.1.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 2e1a90f846fafb06f951b62bf7e398820bc7164235b71e1acae6deba7445bbae |
|
MD5 | 2e50e1867ad643f7fa51c2890e42d227 |
|
BLAKE2b-256 | 09e556f8e744eff8557d07029f438de113fdeeb15852a0db3114a772f5e6d0aa |