mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-22 07:51:00 +00:00
Fix metrics endpoint in non-gunicorn processes
This commit is contained in:
parent
ea9654277b
commit
8ace1bddf9
1 changed files with 6 additions and 1 deletions
|
@ -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")
|
||||||
|
@ -206,7 +212,6 @@ def create_app(args):
|
||||||
authorization = request.headers.get('Authorization')
|
authorization = request.headers.get('Authorization')
|
||||||
if authorization != "Bearer " + args.metrics_auth_token:
|
if authorization != "Bearer " + args.metrics_auth_token:
|
||||||
abort(401, description=_("Unauthorized"))
|
abort(401, description=_("Unauthorized"))
|
||||||
|
|
||||||
registry = CollectorRegistry()
|
registry = CollectorRegistry()
|
||||||
multiprocess.MultiProcessCollector(registry)
|
multiprocess.MultiProcessCollector(registry)
|
||||||
return Response(generate_latest(registry), mimetype=CONTENT_TYPE_LATEST)
|
return Response(generate_latest(registry), mimetype=CONTENT_TYPE_LATEST)
|
||||||
|
|
Loading…
Reference in a new issue