Skip to content

Instantly share code, notes, and snippets.

@drawks
Last active January 20, 2017 19:15
Show Gist options
  • Save drawks/533b8b519a1bf44f9b1fd139a7abda31 to your computer and use it in GitHub Desktop.
Save drawks/533b8b519a1bf44f9b1fd139a7abda31 to your computer and use it in GitHub Desktop.
minimal prometheus instrumentation of a bottle application
from bottle import route, run, template, Bottle
from prometheus_client import multiprocess
from prometheus_client import generate_latest, REGISTRY, Gauge, Counter
application = Bottle()
IN_PROGRESS = Gauge("inprogress_requests", "help")
REQUESTS = Counter('http_requests_total', 'Description of counter', ['method', 'endpoint'])
@IN_PROGRESS.track_inprogress()
@application.route('/hello/<name>')
def index(name):
REQUESTS.labels(method='GET', endpoint="hello").inc()
return template('<b>Hello {{name}}</b>!', name=name)
@IN_PROGRESS.track_inprogress()
@application.route('/metrics')
def metrics():
return generate_latest(REGISTRY)
application.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment