mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
Rewiring how we do statsd
- decorater added to the DAO for notifications
This commit is contained in:
30
app/statsd_decorators.py
Normal file
30
app/statsd_decorators.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import functools
|
||||
|
||||
from app import statsd_client
|
||||
from flask import current_app
|
||||
from monotonic import monotonic
|
||||
|
||||
|
||||
def statsd_timer(namespace):
|
||||
def time_function(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
start_time = monotonic()
|
||||
res = func(*args, **kwargs)
|
||||
elapsed_time = monotonic() - start_time
|
||||
current_app.logger.info(
|
||||
"{namespace} call {func} took {time}".format(
|
||||
namespace=namespace, func=func.__name__, time="{0:.4f}".format(elapsed_time)
|
||||
)
|
||||
)
|
||||
statsd_client.incr('notifications.{namespace}.{func}'.format(
|
||||
namespace=namespace, func=func.__name__)
|
||||
)
|
||||
statsd_client.timing('notifications.{namespace}.{func}'.format(
|
||||
namespace=namespace, func=func.__name__), elapsed_time
|
||||
)
|
||||
return res
|
||||
wrapper.__wrapped__.__name__ = func.__name__
|
||||
return wrapper
|
||||
|
||||
return time_function
|
||||
Reference in New Issue
Block a user