pub fn get_pool_stats(
pool: &BrowserPool,
) -> Result<PoolStatsResponse, PdfServiceError>Expand description
Get current browser pool statistics.
Returns real-time metrics about the browser pool state including available browsers, active browsers, and total count.
§Thread Safety
This function briefly acquires the pool lock to read statistics. It’s safe to call frequently for monitoring purposes.
§Blocking Behavior
This function is fast (< 1ms) as it reads from the pool’s internal state. Safe to call frequently from health check endpoints.
§Arguments
pool- Reference to the browser pool
§Returns
Ok(PoolStatsResponse)- Current pool statistics
§Examples
§Basic Usage
ⓘ
use html2pdf_api::service::get_pool_stats;
let stats = get_pool_stats(&pool)?;
println!("Available: {}", stats.available);
println!("Active: {}", stats.active);
println!("Total: {}", stats.total);§Monitoring Integration
ⓘ
use prometheus::{Gauge, register_gauge};
lazy_static! {
static ref POOL_AVAILABLE: Gauge = register_gauge!(
"browser_pool_available",
"Number of available browsers in pool"
).unwrap();
static ref POOL_ACTIVE: Gauge = register_gauge!(
"browser_pool_active",
"Number of active browsers in pool"
).unwrap();
}
fn update_metrics(pool: &Mutex<BrowserPool>) {
if let Ok(stats) = get_pool_stats(pool) {
POOL_AVAILABLE.set(stats.available as f64);
POOL_ACTIVE.set(stats.active as f64);
}
}§Capacity Check
ⓘ
let stats = get_pool_stats(&pool)?;
if stats.available == 0 {
log::warn!("No browsers available, requests may be delayed");
}
let utilization = stats.active as f64 / stats.total.max(1) as f64;
if utilization > 0.8 {
log::warn!("Pool utilization at {:.0}%, consider scaling", utilization * 100.0);
}