Exemple #1
0
def integrate_prometheus_metrics(app: Flask, restful_api: Api):
    # metrics = RESTfulPrometheusMetrics(app, restful_api)
    metrics = PrometheusMetrics(app)
    metrics.info('app_info', 'Application info', version='1.0.3')

    metrics.register_default(
        metrics.summary('by_path_method_time_stamp_summary',
                        'Request summary by request paths, method, timestamp',
                        labels={
                            'path': lambda: request.path,
                            'method': lambda: request.method,
                            'status': lambda r: r.status_code,
                            'time_stamp': lambda: time.time()
                        }))

    return metrics
import logging
import os
import time

from flask import Flask, request
from prometheus_flask_exporter import PrometheusMetrics

app = Flask(__name__)
metrics = PrometheusMetrics(app)

metrics.register_default(
    metrics.counter('by_path_counter',
                    'Request count by request paths',
                    labels={'path': lambda: request.path}))


@app.route('/handler')
def handler():
    return 'OK'


if __name__ == '__main__':
    logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)
    app.run(host='0.0.0.0', port=os.getenv("HTTP_PORT", 8081))