Last9 Python CDK is a way to emit commonly aggregated metrics straight from your python application that serves HTTP traffic.

Why

Traditional metrics emitters emit, per-path or handler-based metrics. Both these approaches have their drawbacks.

What metrics does CDK emit?

RED Metrics

The very first metrics to be emitted are Rate, Error, and Duration. The following two metrics are enough to populate that.

http_requests_total = Counter(
  "http_requests_total", "Total HTTP requests per path",
  ["per", "hostname", "domain", "method", "program", "status"]
)

http_requests_duration = Histogram(
	"http_requests_duration", "HTTP requests duration per path",
  ["per", "hostname", "domain", "method", "program", "status"]
)

How are metrics exposed?

CDK emits metrics in Openmetrics Prometheus Exposition format. The metric port and endpoint expose the freshest metrics to be pulled by a Prometheus.

You can read more about the Prometheus exposition format on the link

Python Support

The most common frameworks in Python are WSGI-based. While WSGI-based implementation can have a generic enough way to capture duration, status_code, method, domain name, etc. It cannot produce the path pattern used for the handler invocation, that information only resides with the Mux involved.

Hence, there may be parts to the CDK which are activated ONLY when supported frameworks are detected or declared.

**# Only line that needs to be changed**
from last9.wsgi.middleware import RedMiddleware
app.wsgi_app = RedMiddleware(app)
Name Supported Mux Supported
Flask Yes Yes
Tornado - -
Django - -
Pyramid - -
Bottle - -
FastAPI - -
Falcon - -

An Example Application

  1. pip install last9