File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 1717from gen3workflow .routes .system import router as system_router
1818from gen3workflow .auth import Auth
1919
20+ from prometheus_client import CollectorRegistry , make_asgi_app , multiprocess
21+
2022
2123def get_app (httpx_client = None ) -> FastAPI :
2224 logger .info ("Initializing app" )
@@ -73,7 +75,9 @@ def get_app(httpx_client=None) -> FastAPI:
7375 logger .debug (
7476 f"Vieweing metrics associated with the registry { list (app .metrics ._registry .collect ())= } "
7577 )
76- app .mount ("/metrics" , app .metrics .get_asgi_app ())
78+ metrics_app = make_metrics_app (config ["PROMETHEUS_MULTIPROC_DIR" ])
79+ app .mount ("/metrics" , metrics_app )
80+ # app.mount("/metrics", app.metrics.get_asgi_app())
7781
7882 @app .middleware ("http" )
7983 async def middleware_log_response_and_api_metric (
@@ -117,4 +121,14 @@ async def middleware_log_response_and_api_metric(
117121 return app
118122
119123
124+ def make_metrics_app (prometheus_multiproc_dir ):
125+ """
126+ Required for Prometheus multiprocess setup
127+ See: https://prometheus.github.io/client_python/multiprocess/
128+ """
129+ registry = CollectorRegistry ()
130+ multiprocess .MultiProcessCollector (registry , prometheus_multiproc_dir )
131+ return make_asgi_app (registry = registry )
132+
133+
120134app = get_app ()
You can’t perform that action at this time.
0 commit comments