forked from ITISFoundation/osparc-simcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ add
metrics
endpoints to fastapi apps for promethius scraping (IT…
- Loading branch information
1 parent
53ec3e2
commit 7f3d293
Showing
33 changed files
with
190 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,6 @@ | |
|
||
fastapi | ||
httpx | ||
prometheus-client | ||
prometheus-fastapi-instrumentator | ||
uvicorn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/service-library/src/servicelib/fastapi/prometheus_instrumentation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# pylint: disable=protected-access | ||
|
||
|
||
from fastapi import FastAPI | ||
from prometheus_fastapi_instrumentator import Instrumentator | ||
|
||
|
||
def setup_prometheus_instrumentation(app: FastAPI): | ||
|
||
instrumentator = ( | ||
Instrumentator( | ||
should_instrument_requests_inprogress=True, inprogress_labels=False | ||
) | ||
.instrument(app) | ||
.expose(app, include_in_schema=False) | ||
) | ||
|
||
def _unregister(): | ||
for collector in list(instrumentator.registry._collector_to_names.keys()): | ||
instrumentator.registry.unregister(collector) | ||
|
||
# avoid registering collectors multiple times when running unittests consecutively (https://stackoverflow.com/a/62489287) | ||
app.add_event_handler("shutdown", _unregister) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.