Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Statsd middleware for request timing.
- Loading branch information
Showing
4 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
Middleware for sending request statistics to statsd | ||
""" | ||
from __future__ import absolute_import | ||
import time | ||
import statsd | ||
|
||
|
||
class StatsdMiddleware(object): | ||
""" | ||
This logging middleware will log request durations to the configured statsd | ||
instance. | ||
""" | ||
|
||
def __init__(self, | ||
application, | ||
statsd_host, | ||
statsd_port): | ||
self.application = application | ||
self.statsd_client = statsd.StatsClient(statsd_host, statsd_port, prefix='galaxy') | ||
|
||
def __call__(self, environ, start_response): | ||
import pprint | ||
pprint.pprint(environ) | ||
start_time = time.time() | ||
req = self.application(environ, start_response) | ||
dt = int((time.time() - start_time) * 1000) | ||
self.statsd_client.timing(environ.get('PATH_INFO', "NOPATH"), dt) | ||
return req |
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