-
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.
Browse files
Browse the repository at this point in the history
Add use_prometheus_metrics function, to automaticaly enable metrics
- Loading branch information
Showing
5 changed files
with
277 additions
and
260 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 |
---|---|---|
@@ -1,7 +1,27 @@ | ||
from typing import Optional | ||
|
||
from blacksheep.server import Application | ||
|
||
from .middleware import PrometheusMiddleware | ||
from .view import metrics | ||
|
||
|
||
def use_prometheus_metrics( | ||
app: Application, | ||
*, | ||
endpoint: str = "/metrics/", | ||
middleware: Optional[PrometheusMiddleware] = None, | ||
) -> None: | ||
""" | ||
Configures the given application to use Prometheus and provide services that can be | ||
injected in request handlers. | ||
""" | ||
middleware = middleware or PrometheusMiddleware() | ||
app.middlewares.append(middleware) | ||
app.router.add_get(endpoint, metrics) | ||
|
||
|
||
__all__ = [ | ||
'metrics', | ||
'use_prometheus_metrics', | ||
'PrometheusMiddleware', | ||
] |
Oops, something went wrong.