TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/cloudflare/pingora/llms.txt
Use this file to discover all available pages before exploring further.
pingora-prometheus crate provides a dedicated Prometheus HTTP scrape server that can run alongside your Pingora proxy services. It gathers all metrics registered through the prometheus crate and exposes them at an HTTP endpoint so that a Prometheus server can scrape them. This lets you instrument your proxy with counters, gauges, and histograms and have them automatically appear in the metrics output without any additional wiring.
Adding the Dependency
Addpingora-prometheus to your Cargo.toml:
The
pingora-prometheus crate re-exports the prometheus crate as pingora_prometheus::prometheus. Using this re-export ensures your metrics are registered in the same global registry that the scrape endpoint reads from, avoiding version mismatches that would cause metrics to silently not appear.Setting Up the Endpoint
Pingora’s Prometheus support works as a first-class service. You create aprometheus_http_service(), bind it to a TCP address, and register it with your server — it then runs on its own listener in parallel with your proxy service:
Defining Static Metrics
The simplest way to instrument your application is with static metrics. A static metric is declared once as a globalLazy value. It is automatically registered in the global Prometheus registry and will appear at the scrape endpoint without any additional setup.
register_int_gauge! macro (and equivalents such as register_counter!, register_histogram!) come from the prometheus crate. Because they are called inside a Lazy initializer, registration happens on first use and the process will panic if registration fails — which is the desired behavior for a static metric whose name must be unique.
Using Metrics in Proxy Filters
Once a static metric is declared, you can observe or mutate it from anyProxyHttp callback. For example, you can increment a request counter inside request_filter and record upstream response latency inside logging:
Using Metrics with Dynamic Labels
When you need per-label metric instances (e.g. a counter broken down by status code or upstream host), use the vector variants such asIntCounterVec or HistogramVec. These are also declared as Lazy statics and queried with .with_label_values(&[...]) at observation time:
All
register_*! macros are provided by the prometheus crate. Refer to the prometheus crate documentation for the full list of metric types — counters, gauges, histograms, and their Vec (labeled) variants.