-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3964 from erasche/graphite
Graphite support
- Loading branch information
Showing
6 changed files
with
65 additions
and
0 deletions.
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
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ raven | |
pbs_python | ||
drmaa | ||
statsd | ||
graphitesend | ||
azure-storage==0.32.0 | ||
# PyRods not in PyPI | ||
python-ldap==2.4.27 |
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,38 @@ | ||
""" | ||
Middleware for sending request statistics to graphite | ||
""" | ||
from __future__ import absolute_import | ||
|
||
import time | ||
|
||
try: | ||
import graphitesend | ||
except ImportError: | ||
# This middleware will never be used without graphite. This block allows | ||
# unit tests pass on systems without it. | ||
graphitesend = None | ||
|
||
|
||
class GraphiteMiddleware(object): | ||
""" | ||
This middleware will log request durations to the configured graphite | ||
instance. | ||
""" | ||
|
||
def __init__(self, | ||
application, | ||
graphite_host, | ||
graphite_port, | ||
graphite_prefix): | ||
if not graphitesend: | ||
raise ImportError("graphite middleware configured, but no graphite python module found. " | ||
"Please install the python graphitesend module to use this functionality.") | ||
self.application = application | ||
self.graphite_client = graphitesend.init(graphite_server=graphite_host, graphite_port=int(graphite_port), prefix=graphite_prefix.rstrip('.')) | ||
|
||
def __call__(self, environ, start_response): | ||
start_time = time.time() | ||
req = self.application(environ, start_response) | ||
dt = int((time.time() - start_time) * 1000) | ||
self.graphite_client.send(environ.get('controller_action_key', None) or environ.get('PATH_INFO', "NOPATH").strip('/').replace('/', '.'), 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