add shoddy statsd support
This commit is contained in:
parent
719c54b046
commit
8c0c521f6f
3
app.py
3
app.py
|
@ -9,6 +9,7 @@ from flask_limiter import Limiter
|
|||
from flask_limiter.util import get_remote_address
|
||||
from lib import get_viewer
|
||||
import os
|
||||
from lib.statsd import StatsdMiddleware
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
@ -89,3 +90,5 @@ def install_security_headers(resp):
|
|||
resp.headers.set('x-xss-protection', '1')
|
||||
|
||||
return resp
|
||||
|
||||
app.wsgi_app = StatsdMiddleware(app.wsgi_app)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
import time
|
||||
from statsd.defaults.env import statsd
|
||||
|
||||
class StatsdMiddleware(object):
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
timer_name = 'forget.http.{}.{}'.format(
|
||||
environ.get('PATH_INFO').replace('/', '.').strip('.') or 'index',
|
||||
environ.get('REQUEST_METHOD'))
|
||||
with statsd.timer(timer_name):
|
||||
response = self.app(environ, start_response)
|
||||
|
||||
return response
|
||||
|
|
@ -42,3 +42,4 @@ urllib3==1.22
|
|||
vine==1.1.4
|
||||
Werkzeug==0.12.2
|
||||
git+https://github.com/codl/Mastodon.py.git@forget
|
||||
statsd=3.2.1
|
||||
|
|
Loading…
Reference in New Issue