Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
56 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,3 +87,6 @@ ENV/ | |
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# Misc | ||
.DS_Store |
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 was deleted.
Oops, something went wrong.
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,21 @@ | ||
from flask import Flask | ||
from middleware import setup_metrics | ||
|
||
app = Flask(__name__) | ||
setup_metrics(app) | ||
|
||
@app.route('/test/') | ||
def test(): | ||
return 'rest' | ||
|
||
@app.route('/test1/') | ||
def test1(): | ||
1/0 | ||
return 'rest' | ||
|
||
@app.errorhandler(500) | ||
def handle_500(error): | ||
return str(error), 500 | ||
|
||
if __name__ == '__main__': | ||
app.run() |
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,23 @@ | ||
from flask import request | ||
import time | ||
import sys | ||
|
||
def start_timer(): | ||
request.start_time = time.time() | ||
|
||
def stop_timer(response): | ||
resp_time = time.time() - request.start_time | ||
sys.stderr.write("Response time: %ss\n" % resp_time) | ||
return response | ||
|
||
def record_request_data(response): | ||
sys.stderr.write("Request path: %s Request method: %s Response status: %s\n" % | ||
(request.path, request.method, response.status_code)) | ||
return response | ||
|
||
def setup_metrics(app): | ||
app.before_request(start_timer) | ||
# The order here matters since we want stop_timer | ||
# to be executed first | ||
app.after_request(record_request_data) | ||
app.after_request(stop_timer) |
File renamed without changes.