Skip to content

Instantly share code, notes, and snippets.


rchakode/ Secret

Last active Sep 21, 2019
What would you like to do?
Example Prometheus exporter that exports metrics of a Flask application
import prometheus_client
import werkzeug.wsgi
import flask
import random
import time
import threading
SERVICE_UPTIME = prometheus_client.Gauge('service_uptime',
'Hold the time elasted since service startup')
RESPONSE_TIME = prometheus_client.Gauge('response_time_last',
'Hold the last request response time')
# Create Flask app
app = flask.Flask(__name__)
def hello():
return "Hello World!"
# Prometheus wsgi middleware to route /metrics requests
app_dispatch = werkzeug.wsgi.DispatcherMiddleware(app, {
'/metrics': prometheus_client.make_wsgi_app()
def update_uptime():
while True:
uptime_updater = threading.Thread(target=update_uptime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.