Skip to content

Commit

Permalink
release 0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarratt committed Aug 14, 2016
1 parent 9a2bcaf commit 172738b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 3 deletions.
15 changes: 15 additions & 0 deletions .gitignore
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.
40 changes: 40 additions & 0 deletions flask_prometheus/__init__.py
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()
10 changes: 7 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand All @@ -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',
Expand All @@ -34,5 +37,6 @@
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
]
],
keywords='prometheus monitoring'
)

0 comments on commit 172738b

Please sign in to comment.