Skip to main content

Prometheus integration for blacksheep

Project description

Blacksheep Prometheus

Build Status codecov Package Version PyPI Version

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 default /metrics/ endpoint.

from blacksheep.server import Application
from blacksheep_prometheus import use_prometheus_metrics

app = 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:

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

blacksheep-prometheus-0.1.7.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

blacksheep_prometheus-0.1.7-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file blacksheep-prometheus-0.1.7.tar.gz.

File metadata

  • Download URL: blacksheep-prometheus-0.1.7.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.13 Linux/5.13.0-1022-azure

File hashes

Hashes for blacksheep-prometheus-0.1.7.tar.gz
Algorithm Hash digest
SHA256 2fbe6ec8860fb30f4e1d91a7d9efeec4d7709f437b131907b6f7d0f31d029d62
MD5 5d427da49d126bbb905601967d0500f4
BLAKE2b-256 665e634f21c1837ea3b2f23e24b436ed5277d57bbc20baccbc4a6820bd283e50

See more details on using hashes here.

File details

Details for the file blacksheep_prometheus-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for blacksheep_prometheus-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1492edebac90d6d55019af63abc72bd001c4d4c44570abafb29d8d43fa771a0a
MD5 c601c317950ba4fc23ca86316b0cd483
BLAKE2b-256 8fb29529eef65c3c5f5f00ef7faa52da75006b6e15c572e16d67ae14ff7ff80a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page