actix-web-prom
Actix Web middleware that exposes Prometheus metrics for your HTTP handlers.
Repository Health
Technical Analysis
actix-web-prom is middleware for the Actix Web framework that instruments your application and exposes Prometheus metrics. Out of the box it tracks total HTTP requests and request duration, each labeled by endpoint, method, and status, and it can auto-expose a configurable metrics endpoint. You can add constant labels, register your own metrics, and customize cardinality to fit your monitoring setup.
What You Get
- A
PrometheusMetricsmiddleware you attach with Actix Web’s.wrap() - Default request-count and request-duration metrics labeled by endpoint, method, and status
- An auto-exposed, configurable metrics endpoint in Prometheus text format
- A builder for setting the namespace, endpoint path, and constant labels
- Support for registering and exposing your own custom Prometheus metrics
Common Use Cases
- Exposing request throughput and latency metrics from an Actix Web service
- Scraping per-endpoint HTTP metrics into Prometheus and Grafana dashboards
- Adding custom application metrics alongside default HTTP instrumentation
Under The Hood
Architecture
The implementation is concentrated in a single sizable src/lib.rs that defines PrometheusMetrics and its builder, plus the Actix middleware Transform and Service implementations that wrap each request. On every request it records the endpoint, method, and status into Prometheus counters and histograms, and it intercepts the configured metrics path to render the registry in Prometheus text format. Examples under examples/ show wiring into an app.
Tech Stack
It targets the Rust 2024 edition and integrates with actix-web 4, using the prometheus crate 0.14 for metric primitives, strfmt for label formatting, regex for endpoint matching, plus futures-core and pin-project-lite for the middleware future. An optional process feature enables process-level metrics from the prometheus crate.
Code Quality
Tests are embedded in src/lib.rs and exercise the middleware behavior and metric output, and a README.tpl with cargo-readme keeps the documentation generated from doc comments. A pinned rust-toolchain.toml and rustfmt configuration indicate attention to reproducible builds and consistent style.
API Design
The PrometheusMetricsBuilder offers a clear, chainable configuration for namespace, endpoint, and constant labels, and attaching the middleware is a single .wrap() call. The README walks through default metrics, custom metric registration, and cardinality considerations, so both the common case and advanced customization are well documented.