-
-
Notifications
You must be signed in to change notification settings - Fork 766
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 #64 from zalando/metrics
Add UWSGI metrics collector
- Loading branch information
Showing
2 changed files
with
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
import functools | ||
|
||
try: | ||
import uwsgi_metrics | ||
HAS_UWSGI_METRICS = True | ||
except: | ||
HAS_UWSGI_METRICS = False | ||
|
||
|
||
class UWSGIMetricsCollector: | ||
def __init__(self, path, method): | ||
self.path = path | ||
self.method = method | ||
self.key = '{}.{}'.format(self.path.strip('/').replace('/', '.').replace('<', '{').replace('>', '}'), | ||
self.method.upper()) | ||
|
||
@staticmethod | ||
def is_available(): | ||
return HAS_UWSGI_METRICS | ||
|
||
def __call__(self, function): | ||
""" | ||
:type function: types.FunctionType | ||
:rtype: types.FunctionType | ||
""" | ||
|
||
@functools.wraps(function) | ||
def wrapper(*args, **kwargs): | ||
with uwsgi_metrics.timing('connexion.response', self.key): | ||
return function(*args, **kwargs) | ||
|
||
return wrapper |
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