mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(fastapi): utilize PROMETHEUS_MULTIPROC_DIR in our own /metrics
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
1be4ac2fde
commit
dc397f6bd8
3 changed files with 34 additions and 3 deletions
|
@ -9,6 +9,7 @@ from urllib.parse import quote_plus
|
|||
from fastapi import FastAPI, HTTPException, Request
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from prometheus_client import multiprocess
|
||||
from sqlalchemy import and_, or_
|
||||
from starlette.middleware.authentication import AuthenticationMiddleware
|
||||
from starlette.middleware.sessions import SessionMiddleware
|
||||
|
@ -29,7 +30,7 @@ app = FastAPI(exception_handlers=errors.exceptions)
|
|||
# library with custom collectors and expose /metrics.
|
||||
instrumentator().add(http_api_requests_total())
|
||||
instrumentator().add(http_requests_total())
|
||||
instrumentator().instrument(app).expose(app)
|
||||
instrumentator().instrument(app)
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
|
@ -79,6 +80,12 @@ async def app_startup():
|
|||
get_engine()
|
||||
|
||||
|
||||
def child_exit(server, worker): # pragma: no cover
|
||||
""" This function is required for gunicorn customization
|
||||
of prometheus multiprocessing. """
|
||||
multiprocess.mark_process_dead(worker.pid)
|
||||
|
||||
|
||||
@app.exception_handler(HTTPException)
|
||||
async def http_exception_handler(request, exc):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue