Expand description
§Metrics Module
This module provides comprehensive Prometheus metrics integration for Actix web applications. It enables robust monitoring capabilities with automatic metric collection, exposition, and visualization through an integrated dashboard.
§Features
- Prometheus Integration: Full support for collecting and exposing metrics in Prometheus format
- Interactive Dashboard: Built-in web UI for visualizing metrics in real-time
- Rate Metrics: Automatic calculation and tracking of per-second rates from counter values
- Customizable Histograms: Fine-grained control over histogram bucket configuration
- Easy Integration: Seamlessly integrates with Actix web applications via a simple API
- Thread-Safe: Designed for concurrent access with proper synchronization
- Low Overhead: Minimal performance impact on your application
§Architecture
The module uses a multi-recorder approach with a fanout pattern to capture both metric values and their associated metadata (like units). This information is then made available both in Prometheus format for scraping and through a dashboard for human-readable visualization.
§Getting Started
Simply add the metrics scope to your Actix application as shown in the examples below.
Re-exports§
pub use metrics;pub use metrics_exporter_prometheus;pub use metrics_util;
Macros§
- absolute_
counter_ with_ rate - Macro for recording an absolute counter value with automatic rate tracking
- counter_
with_ rate - Macro for recording a counter with automatic rate tracking
Structs§
- Dashboard
Input - Configuration options for the metrics dashboard
- Rate
Tracker - Rate tracking utility for calculating per-second rates from counter values
- get_
dashboard - Handler for the metrics dashboard index page
- get_
dashboard_ assets - Handler for serving dashboard assets (JS, CSS, etc.)
- get_
prometheus_ metrics - Endpoint for exposing Prometheus metrics
Functions§
- create_
metrics_ actx_ scope - Creates an Actix web scope for metrics endpoints
- update_
rate_ tracker - Updates a rate tracker and returns the calculated rate