Merge pull request #403 from pierotofy/metricsfix

Fix metrics endpoint in non-gunicorn processes
This commit is contained in:
Piero Toffanin 2023-02-06 00:39:40 +01:00 committed by GitHub
commit 90fea3226f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -197,6 +197,12 @@ def create_app(args):
measure_request = None measure_request = None
gauge_request = None gauge_request = None
if args.metrics: if args.metrics:
if os.environ.get("PROMETHEUS_MULTIPROC_DIR") is None:
default_mp_dir = os.path.abspath(os.path.join("db", "prometheus"))
if not os.path.isdir(default_mp_dir):
os.mkdir(default_mp_dir)
os.environ["PROMETHEUS_MULTIPROC_DIR"] = default_mp_dir
from prometheus_client import CONTENT_TYPE_LATEST, Summary, Gauge, CollectorRegistry, multiprocess, generate_latest from prometheus_client import CONTENT_TYPE_LATEST, Summary, Gauge, CollectorRegistry, multiprocess, generate_latest
@bp.route("/metrics") @bp.route("/metrics")