Pilares
Clientes e bibliotecas - Instrumentação
from flask import Flask, jsonify, request
from prometheus_client import make_wsgi_app, Counter, Histogram
from werkzeug.middleware.dispatcher import DispatcherMiddleware
import time
app = Flask(__name__)
app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {
'/metrics': make_wsgi_app()
})
REQUEST_LATENCY = Histogram(
'app_request_latency_seconds',
'Application Request Latency',
['method', 'endpoint']
)
@app.route('/')
def hello():
start_time = time.time()
response = jsonify(message='Hello, world!')
REQUEST_LATENCY.labels('GET', '/').observe(time.time() - start_time)
return response
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)