add shoddy statsd support

This commit is contained in:
codl 2017-08-28 17:13:12 +02:00
parent 719c54b046
commit 8c0c521f6f
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
3 changed files with 20 additions and 0 deletions

3
app.py
View File

@ -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)

16
lib/statsd.py Normal file
View File

@ -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

View File

@ -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