Prometheus integration for blacksheep
Project description
Blacksheep Prometheus
Introduction
Prometheus integration for Blacksheep.
Requirements
- Python 3.7+
- Blacksheep 1.0.7+
Installation
$ pip install blacksheep-prometheus
Usage
A complete example that exposes prometheus metrics endpoint under /metrics/
path.
from blacksheep.server import Application
from blacksheep_prometheus import PrometheusMiddleware, metrics
app = Application()
app.middlewares.append(PrometheusMiddleware())
app.router.add_get('/metrics/', metrics)
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:
from prometheus_client import Counter
from blacksheep.server.responses import redirect
REDIRECT_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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file blacksheep-prometheus-0.1.5.tar.gz
.
File metadata
- Download URL: blacksheep-prometheus-0.1.5.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.8.10 Linux/5.8.0-1033-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f5e4bf51c1ec78c95bc7ace7cff9692d22dafa8dea4041e86f02bd12f0065c2 |
|
MD5 | 3248c873d8e3b5a301f857bc91a55727 |
|
BLAKE2b-256 | 0a61aebb2c726ab2febaf322f64d6ed6f4c69fdee28d135b1ca0e30366b8800a |
File details
Details for the file blacksheep_prometheus-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: blacksheep_prometheus-0.1.5-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.8.10 Linux/5.8.0-1033-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b443ad9a8bd3749e6f8b079927ce180bafdfd2acf213bd3d41c30c6112d4a04 |
|
MD5 | 6a3312b32c5bd290ca89da9cb07f5f75 |
|
BLAKE2b-256 | 2685a8482f1125a03aa3e48efd0f687e9abe959953f3ae0567f17b7385677139 |