Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cdayz/blacksheep-prometheus
Prometheus integration for BlackSheep
https://github.com/cdayz/blacksheep-prometheus
asgi asyncio blacksheep metrics middleware prometheus python3
Last synced: 23 days ago
JSON representation
Prometheus integration for BlackSheep
- Host: GitHub
- URL: https://github.com/cdayz/blacksheep-prometheus
- Owner: Cdayz
- License: mit
- Created: 2021-06-16T10:44:10.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T13:00:57.000Z (almost 2 years ago)
- Last Synced: 2024-11-09T08:07:07.601Z (about 1 month ago)
- Topics: asgi, asyncio, blacksheep, metrics, middleware, prometheus, python3
- Language: Python
- Homepage:
- Size: 121 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Blacksheep Prometheus
[![Build Status](https://github.com/Cdayz/blacksheep-prometheus/workflows/Continuous%20Integration/badge.svg)](https://github.com/Cdayz/blacksheep-prometheus/actions)
[![codecov](https://codecov.io/gh/Cdayz/blacksheep-prometheus/branch/master/graph/badge.svg?token=YJTGKBTQSE)](https://codecov.io/gh/Cdayz/blacksheep-prometheus)
[![Package Version](https://img.shields.io/pypi/v/blacksheep-prometheus?logo=PyPI&logoColor=white)](https://pypi.org/project/blacksheep-prometheus/)
[![PyPI Version](https://img.shields.io/pypi/pyversions/blacksheep-prometheus?logo=Python&logoColor=white)](https://pypi.org/project/blacksheep-prometheus/)## Introduction
Prometheus integration for Blacksheep.
## Requirements
* Python 3.7+
* Blacksheep 1.0.7+## Installation
```console
$ pip install blacksheep-prometheus
```## Usage
A complete example that exposes prometheus metrics endpoint under default `/metrics/` endpoint.
```python
from blacksheep.server import Application
from blacksheep_prometheus import use_prometheus_metricsapp = Application()
use_prometheus_metrics(app)
```### Options
| Option name | Description | Default value |
|-----------------------------------|-----------------------------------------------------|-----------------------------------|
|`requests_total_metric_name` | name of metric for total requests |`'backsheep_requests_total'` |
|`responses_total_metric_name` | name of metric for total responses |`'backsheep_responses_total'` |
|`request_time_seconds_metric_name` | name of metric for request timings |`'backsheep_request_time_seconds'` |
|`exceptions_metric_name` | name of metric for exceptions |`'backsheep_exceptions'` |
|`requests_in_progress_metric_name` | name of metric for in progress requests |`'backsheep_requests_in_progress'` |
|`filter_paths` | list of path's where do not need to collect metrics |`[]` |### Custom metrics
blacksheep-prometheus will export all the prometheus metrics from the process, so custom metrics can be created by using the prometheus_client API.
*Example:*
```python
from prometheus_client import Counter
from blacksheep.server.responses import redirectREDIRECT_COUNT = Counter("redirect_total", "Count of redirects", ("from_view",))
async def some_view(request):
REDIRECT_COUNT.labels(from_view="some_view").inc()
return redirect("https://example.com")
```The new metric will now be included in the the `/metrics` endpoint output:
```
...
redirect_total{from_view="some_view"} 2.0
...
```## Contributing
This project is absolutely open to contributions so if you have a nice idea, create an issue to let the community
discuss it.