Merge in RR/pyinfra from add-prometheus-metrics to master
Squashed commit of the following:
commit 3736e867bfb105f2c2601f6d25343c996027cc5f
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Wed Mar 16 11:35:25 2022 +0100
removed obsolete config entry
commit dc191b17d863ec4f8009fb130c2c3a78d4116969
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Wed Mar 16 11:34:12 2022 +0100
removed obsolete dependency
commit 5ba9765e88da7dd15700b211794f433a6f7ea0df
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Wed Mar 16 11:32:37 2022 +0100
changed error handling for prometheus endpoint
commit 894a6b5d4c7026b9a703a8b2cd70641e7ed7323b
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date: Wed Mar 16 11:16:39 2022 +0100
fixed definition order broken by auto-refac; reduced prometheus code to only forwarding to analysis endpoint
commit 9f3c884c75289c7b558e8cc8fb0154b5ddd3a323
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Mar 16 08:59:45 2022 +0100
black is back
commit 5950799e03f3578ff58f19430494c6b0c223c0f6
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Mar 16 08:59:11 2022 +0100
add prometheus memory peak monitoring, combine report with analysis report
58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
import logging
|
|
|
|
import requests
|
|
from flask import Flask, jsonify
|
|
from waitress import serve
|
|
|
|
from pyinfra.config import CONFIG
|
|
|
|
|
|
logger = logging.getLogger(__file__)
|
|
logger.setLevel(CONFIG.service.logging_level)
|
|
|
|
|
|
def run_probing_webserver(app, host=None, port=None, mode=None):
|
|
if not host:
|
|
host = CONFIG.probing_webserver.host
|
|
|
|
if not port:
|
|
port = CONFIG.probing_webserver.port
|
|
|
|
if not mode:
|
|
mode = CONFIG.probing_webserver.mode
|
|
|
|
if mode == "development":
|
|
app.run(host=host, port=port, debug=True)
|
|
|
|
elif mode == "production":
|
|
serve(app, host=host, port=port)
|
|
|
|
|
|
def set_up_probing_webserver():
|
|
# TODO: implement meaningful checks
|
|
app = Flask(__name__)
|
|
|
|
@app.route("/ready", methods=["GET"])
|
|
def ready():
|
|
resp = jsonify("OK")
|
|
resp.status_code = 200
|
|
return resp
|
|
|
|
@app.route("/health", methods=["GET"])
|
|
def healthy():
|
|
resp = jsonify("OK")
|
|
resp.status_code = 200
|
|
return resp
|
|
|
|
@app.route("/prometheus", methods=["GET"])
|
|
def get_metrics_from_analysis_endpoint():
|
|
try:
|
|
resp = requests.get(f"{CONFIG.rabbitmq.callback.analysis_endpoint}/prometheus")
|
|
resp.raise_for_status()
|
|
return resp.text
|
|
except Exception as err:
|
|
logger.warning(f"Got no metrics from analysis prometheus endpoint: {err}")
|
|
return resp
|
|
|
|
return app
|