-
Notifications
You must be signed in to change notification settings - Fork 24
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
6 changed files
with
62 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
tests_output/ | ||
__pycache__/ | ||
|
||
.tox | ||
.coverage | ||
|
||
*.py[co] | ||
*.egg-info | ||
*.swp | ||
|
||
dist/ | ||
docs/_build/ | ||
|
||
virtualenv/ | ||
venv/ |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,40 @@ | ||
import time | ||
|
||
from prometheus_client import Counter, Histogram | ||
from prometheus_client import start_http_server | ||
from flask import request | ||
|
||
FLASK_REQUEST_LATENCY = Histogram('flask_request_latency_seconds', 'Flask Request Latency', | ||
['method', 'endpoint']) | ||
FLASK_REQUEST_COUNT = Counter('flask_request_count', 'Flask Request Count', | ||
['method', 'endpoint', 'http_status']) | ||
|
||
|
||
def before_request(): | ||
request.start_time = time.time() | ||
|
||
|
||
def after_request(response): | ||
request_latency = time.time() - request.start_time | ||
FLASK_REQUEST_LATENCY.labels(request.method, request.path).observe(request_latency) | ||
FLASK_REQUEST_COUNT.labels(request.method, request.path, response.status_code).inc() | ||
|
||
return response | ||
|
||
def monitor(app, port=8000, addr=''): | ||
app.before_request(before_request) | ||
app.after_request(after_request) | ||
start_http_server(port, addr) | ||
|
||
if __name__ == '__main__': | ||
from flask import Flask | ||
app = Flask(__name__) | ||
|
||
monitor(app, port=8000) | ||
|
||
@app.route('/') | ||
def index(): | ||
return "Hello" | ||
|
||
# Run the application! | ||
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
url='http://github.com/sbarratt/flask-prometheus', | ||
license='BSD', | ||
author='Shane Barratt', | ||
author_email='[email protected]' | ||
author_email='[email protected]', | ||
maintainer='Shane Barratt', | ||
maintainer_email='[email protected]', | ||
description='Prometheus client instrumentation for flask.', | ||
|
@@ -19,13 +19,16 @@ | |
'prometheus-client>=0.0.14' | ||
], | ||
classifiers=[ | ||
'Environment :: Web Environment', | ||
'Intended Audience :: Developers', | ||
'Development Status :: 3 - Alpha', | ||
'License :: OSI Approved :: BSD License', | ||
|
||
'Operating System :: OS Independent', | ||
'Environment :: Web Environment', | ||
'Topic :: System :: Monitoring', | ||
'Topic :: Internet :: WWW/HTTP :: Dynamic Content', | ||
'Topic :: Software Development :: Libraries :: Python Modules', | ||
|
||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 2', | ||
'Programming Language :: Python :: 2.6', | ||
|
@@ -34,5 +37,6 @@ | |
'Programming Language :: Python :: 3.3', | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: 3.5', | ||
] | ||
], | ||
keywords='prometheus monitoring' | ||
) |