Package: pyramid_metrics
Performance metrics for Pyramid using StatsD. The project aims at providing
ways to instrument a Pyramid application in the least intrusive way.PyPI:https://pypi.python.org/pypi/pyramid_metricsGithub:https://github.com/ludia/pyramid_metricsInstallationInstall using setuptools, e.g. (within a virtualenv):$ pip install pyramid_metricsSetupOncepyramid_metricsis installed, you must use theconfig.includemechanism to include it into your Pyramid project’s configuration.  In your
Pyramid project’s__init__.py:config=Configurator(.....)config.include('pyramid_metrics')Alternately you can use thepyramid.includesconfiguration value in your.inifile:[app:myapp]pyramid.includes=pyramid_metricsUsagePyramid_metrics configuration (values are defaults):[app:myapp]metrics.host=localhostmetrics.port=8125metrics.prefix=application.stagemetrics.route_performance=trueRoute performanceIf enabled, the route performance feature will time the request processing.
By using the StatsD Timer type metric, pre-aggregation will provide information
on latency, rate and total number. The information is sent two times: per route
and globally.The key name is composed of the route name,
the HTTP method and the outcome (as HTTP status code or ‘exc’ for exception).Global keyrequest.<HTTP_METHOD>.<STATUS_CODE_OR_EXC>Per route keyroute.<ROUTE_NAME>.request.<HTTP_METHOD>.<STATUS_CODE_OR_EXC>APICounterStatsD type: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))GaugeStatsD type: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)TimerStatsD type: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'Currently implementedCollection utility as a request methodAbility to send metrics per Pyramid routeSimple time marker mechanismSimple counterContext manager for Timing metric typeTODOFull StatsD metric typesExtensions for automatic metrology (SQLAlchemy, MongoDB, Requests…)Whitelist/blacklist of metricsTime allocation per subsystem (using the time marker mechanism)ConsiderationsThe general error policy is: always failsafe. Pyramid_metrics should NEVER
break your application.The DNS resolution is done during configuration to avoid recurring latencies.DevelopmentRun testsThe tests are run by nose and all dependencies are in requirements-test.txt.$pipinstall-rrequirements-test...$nosetests...Run tests with tox$pipinstalltox...$tox# Run on python 2.7 and python 3.4...$tox-epy34# Run on python 3.4 onlyContributorsPior Bastida (@pior)Philippe Gauthier (@deuxpi)Hadrien David (@hadrien)Jay R. Wren (@jrwren)