Skip to content

Instantly share code, notes, and snippets.

@jvanasco
Created May 24, 2013 04:20
Show Gist options
  • Save jvanasco/5641263 to your computer and use it in GitHub Desktop.
Save jvanasco/5641263 to your computer and use it in GitHub Desktop.
using statsd to profile a pyramid app
config.add_subscriber(\
"app.subscribers.statsd_timing",
"pyramid.events.ContextFound")
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)
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