Skip to content

Commit

Permalink
Merge pull request #47 from Cdayz/feature/#8
Browse files Browse the repository at this point in the history
Add use_prometheus_metrics function, to automaticaly enable metrics
  • Loading branch information
Nikita Tomchik authored May 12, 2022
2 parents 8862b0a + 4da6a46 commit 26ff13d
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 260 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ $ pip install blacksheep-prometheus

## Usage

A complete example that exposes prometheus metrics endpoint under `/metrics/` path.
A complete example that exposes prometheus metrics endpoint under default `/metrics/` endpoint.

```python
from blacksheep.server import Application
from blacksheep_prometheus import PrometheusMiddleware, metrics
from blacksheep_prometheus import use_prometheus_metrics

app = Application()

app.middlewares.append(PrometheusMiddleware())
app.router.add_get('/metrics/', metrics)
use_prometheus_metrics(app)
```

### Options
Expand Down
22 changes: 21 additions & 1 deletion blacksheep_prometheus/__init__.py
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',
]
Loading

0 comments on commit 26ff13d

Please sign in to comment.