Skip to content

Instantly share code, notes, and snippets.

@jvanasco
Created May 24, 2013 04:20
Show Gist options
  • Select an option

  • Save jvanasco/5641263 to your computer and use it in GitHub Desktop.

Select an option

Save jvanasco/5641263 to your computer and use it in GitHub Desktop.

Revisions

  1. jvanasco created this gist May 24, 2013.
    3 changes: 3 additions & 0 deletions __init__.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    config.add_subscriber(\
    "app.subscribers.statsd_timing",
    "pyramid.events.ContextFound")
    11 changes: 11 additions & 0 deletions subscribers.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@

    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)
    2 changes: 2 additions & 0 deletions utils.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    import statsd ## https://pypi.python.org/pypi/statsd/2.0.1
    statsd_client = statsd.StatsClient('localhost',8125,prefix="pyramid")