pub struct MetricsServer;Expand description
HTTP server for exposing Prometheus metrics
Implementations§
Source§impl MetricsServer
impl MetricsServer
Sourcepub async fn run(addr: SocketAddr, metrics: Arc<PrometheusMetrics>)
pub async fn run(addr: SocketAddr, metrics: Arc<PrometheusMetrics>)
Starts the metrics server on the given address
This function runs indefinitely until the server is stopped.
§Arguments
addr- The socket address to bind to (e.g., “0.0.0.0:9090”)metrics- The PrometheusMetrics instance to expose
§Panics
Panics if unable to bind to the specified address or if the server fails to start.
Sourcepub async fn run_with_health_checker<F>(
addr: SocketAddr,
metrics: Arc<PrometheusMetrics>,
health_checker: F,
)
pub async fn run_with_health_checker<F>( addr: SocketAddr, metrics: Arc<PrometheusMetrics>, health_checker: F, )
Starts the metrics server with a health checker function
This function runs indefinitely until the server is stopped.
§Arguments
addr- The socket address to bind to (e.g., “0.0.0.0:9090”)metrics- The PrometheusMetrics instance to exposehealth_checker- Function that returns a HealthReport when called
§Panics
Panics if unable to bind to the specified address or if the server fails to start.
Sourcepub async fn run_with_listener(
listener: TcpListener,
metrics: Arc<PrometheusMetrics>,
)
pub async fn run_with_listener( listener: TcpListener, metrics: Arc<PrometheusMetrics>, )
Starts the metrics server with an existing listener
This function runs indefinitely until the server is stopped. Use this when you need to bind the listener before spawning the server task.
§Arguments
listener- A bound TCP listenermetrics- The PrometheusMetrics instance to expose
§Panics
Panics if the server fails to start.
Sourcepub async fn run_with_listener_and_health_checker(
listener: TcpListener,
metrics: Arc<PrometheusMetrics>,
health_checker: Arc<dyn Fn() -> HealthReport + Send + Sync>,
)
pub async fn run_with_listener_and_health_checker( listener: TcpListener, metrics: Arc<PrometheusMetrics>, health_checker: Arc<dyn Fn() -> HealthReport + Send + Sync>, )
Starts the metrics server with an existing listener and health checker
This function runs indefinitely until the server is stopped. Use this when you need to bind the listener before spawning the server task.
§Arguments
listener- A bound TCP listenermetrics- The PrometheusMetrics instance to exposehealth_checker- Function that returns a HealthReport when called
§Panics
Panics if the server fails to start.