Skip to content

bareasgi_prometheus

module bareasgi_prometheus

Summary

bareASGI prometheus middleware

Description

Provides metrics for requests to a bareASGI web service.

function bareasgi_prometheus.add_prometheus_middleware

Summary

Adds prometheus middleware as the first middleware.

bareasgi_prometheus.add_prometheus_middleware(
app: Application,
*,
metric_type: Optional[Type[HttpRequestMetric]],
host: Optional[str],
app_name: Optional[str],
metrics_path: Optional[str]
) -> Application

Parameters

app: Application

The ASGI application

metric_type: Optional[Type[HttpRequestMetric]] (optional)

An optional custom request monitor. Defaults to None.

host: Optional[str] (optional)

An optional path for the metrics. Defaults to None.

app_name: Optional[str] (optional)

The application name. Defaults to None.

metrics_path: Optional[str] (optional)

The path from which the metrics will be served. Defaults to '/metrics'.

Returns

Application: The ASGI application

async function bareasgi_prometheus.prometheus_view

Summary

The endpoint for prometheus stats

async bareasgi_prometheus.prometheus_view(
_request: HttpRequest
) -> HttpResponse

Parameters

_request: HttpRequest

The request.

Returns

HttpResponse: The prometheus statistics

class HttpRequestMetric(TimedMetric)

Summary

Create an HTTP request metric

bareasgi_prometheus.metrics.HttpRequestMetric(
host: str,
app_name: str,
request: HttpRequest
) -> None

Parameters

host: str

The host

app_name: str

The name of the application

request: HttpRequest

The request

property HttpRequestMetric.elapsed

Summary

The elapsed time

elapsed -> float

method HttpRequestMetric.on_enter

Summary

Called at the start of the context

HttpRequestMetric.on_enter() -> Any

Returns

Any:

method HttpRequestMetric.on_exit

Summary

Called at the end of the context

HttpRequestMetric.on_exit() -> Any

Returns

Any:

class PrometheusHttpRequestMetric(HttpRequestMetric)

Summary

Create an HTTP request metric

bareasgi_prometheus.metrics.PrometheusHttpRequestMetric(
host: str,
app_name: str,
request: HttpRequest
) -> None

Parameters

host: str

The host

app_name: str

The name of the application

request: HttpRequest

The request

property PrometheusHttpRequestMetric.elapsed

Summary

The elapsed time

elapsed -> float

method PrometheusHttpRequestMetric.on_enter

Summary

Called at the start of the context

PrometheusHttpRequestMetric.on_enter() -> Any

Returns

Any:

method PrometheusHttpRequestMetric.on_exit

Summary

Called at the end of the context

PrometheusHttpRequestMetric.on_exit() -> Any

Returns

Any:

class PrometheusMiddleware

Summary

Prometheus middleware

bareasgi_prometheus.PrometheusMiddleware(
*,
metric_type: Type[HttpRequestMetric],
host: Optional[str],
app_name: Optional[str]
) -> None

Parameters

metric_type: Type[HttpRequestMetric] (optional)

The metric type. Defaults to None.

host: Optional[str] (optional)

The host. Defaults to None.

app_name: Optional[str] (optional)

The application name. Defaults to None.