Created
May 24, 2013 04:20
-
-
Save jvanasco/5641263 to your computer and use it in GitHub Desktop.
using statsd to profile a pyramid app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config.add_subscriber(\ | |
"app.subscribers.statsd_timing", | |
"pyramid.events.ContextFound") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _statsd_timing_callback(request): | |
timer_diff = int((time.time() - request.timing_ContextFound) * 1000) | |
key = 'routes.%s' % request.matched_route.name | |
key = key.replace(':','_') | |
utils.statsd_client.timing( key , timer_diff ) | |
utils.statsd_client.incr( key ) | |
def statsd_timing(event): | |
event.request.timing_ContextFound = time.time() | |
event.request.add_finished_callback(_statsd_timing_callback) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import statsd ## https://pypi.python.org/pypi/statsd/2.0.1 | |
statsd_client = statsd.StatsClient('localhost',8125,prefix="pyramid") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment