use prometheus::{
register_histogram_vec, register_int_counter, register_int_counter_vec, register_int_gauge,
register_int_gauge_vec, HistogramVec, IntCounter, IntCounterVec, IntGauge, IntGaugeVec,
};
use std::sync::LazyLock;
pub static RPC_REQUESTS_TOTAL: LazyLock<IntCounter> = LazyLock::new(|| {
register_int_counter!("rpc_requests_total", "Total number of forwarded RPC requests").unwrap()
});
pub static RPC_REQUESTS_METHOD: LazyLock<IntCounterVec> = LazyLock::new(|| {
register_int_counter_vec!(
"rpc_requests_method_total",
"Total number of forwarded RPC requests per method",
&["method"]
)
.unwrap()
});
pub static RPC_REQUESTS_SUCCEEDED: LazyLock<IntCounterVec> = LazyLock::new(|| {
register_int_counter_vec!(
"rpc_requests_succeeded_total",
"Total number of successful requests per endpoint",
&["endpoint"]
)
.unwrap()
});
pub static RPC_REQUESTS_FAILED: LazyLock<IntCounterVec> = LazyLock::new(|| {
register_int_counter_vec!(
"rpc_requests_failed_total",
"Total number of failed requests per endpoint",
&["endpoint"]
)
.unwrap()
});
pub static REQUEST_TIMEOUTS: LazyLock<IntCounterVec> = LazyLock::new(|| {
register_int_counter_vec!(
"rpc_request_timeouts_total",
"Total number of request timeouts per endpoint",
&["endpoint"]
)
.unwrap()
});
pub static BATCH_SIZE_EXCEEDED: LazyLock<IntCounter> = LazyLock::new(|| {
register_int_counter!(
"batch_size_exceeded_total",
"Total number of batch requests rejected due to exceeding size limit"
)
.unwrap()
});
pub static UPSTREAM_RATE_LIMITED_TOTAL: LazyLock<IntCounterVec> = LazyLock::new(|| {
register_int_counter_vec!(
"upstream_rate_limited_total",
"Total number of times an upstream provider returned HTTP 429",
&["endpoint"]
)
.unwrap()
});
pub static HEALTHCHECK_FAILED: LazyLock<IntCounterVec> = LazyLock::new(|| {
register_int_counter_vec!(
"rpc_healthcheck_failed_total",
"Total number of failed health checks per endpoint",
&["endpoint"]
)
.unwrap()
});
pub static COOLDOWNS_TRIGGERED: LazyLock<IntCounterVec> = LazyLock::new(|| {
register_int_counter_vec!(
"rpc_endpoint_cooldowns_total",
"Total number of times an endpoint was put into cooldown",
&["endpoint"]
)
.unwrap()
});
pub static COOLDOWN_SECONDS_GAUGE: LazyLock<IntGaugeVec> = LazyLock::new(|| {
register_int_gauge_vec!(
"rpc_endpoint_cooldown_seconds",
"Seconds remaining for endpoint cooldown (0 when not cooling)",
&["endpoint"]
)
.unwrap()
});
pub static HEALTHY_ENDPOINTS: LazyLock<IntGauge> = LazyLock::new(|| {
register_int_gauge!("healthy_endpoints", "Number of currently healthy RPC endpoints").unwrap()
});
pub static TOTAL_ENDPOINTS: LazyLock<IntGauge> = LazyLock::new(|| {
register_int_gauge!("total_endpoints", "Total number of RPC endpoints configured").unwrap()
});
pub static CONCURRENCY_ACTIVE_PERMITS: LazyLock<IntGauge> = LazyLock::new(|| {
register_int_gauge!(
"concurrency_limiter_active_permits",
"Number of currently active in-flight requests"
)
.unwrap()
});
pub static ENDPOINT_RATE_LIMIT_DEFERRED: LazyLock<IntCounterVec> = LazyLock::new(|| {
register_int_counter_vec!(
"endpoint_rate_limit_deferred_total",
"Total requests deferred due to per-endpoint rate limiting",
&["endpoint"]
)
.unwrap()
});
pub static ALL_ENDPOINTS_RATE_LIMITED: LazyLock<IntCounter> = LazyLock::new(|| {
register_int_counter!(
"all_endpoints_rate_limited_total",
"Total times no endpoint was available due to rate limiting"
)
.unwrap()
});
pub static PRIORITY_ENDPOINT_SELECTED: LazyLock<IntCounterVec> = LazyLock::new(|| {
register_int_counter_vec!(
"priority_endpoint_selected_total",
"Total number of times each priority level was selected",
&["endpoint", "priority_rank"]
)
.unwrap()
});
pub static REQUEST_LATENCY_PER_ENDPOINT: LazyLock<HistogramVec> = LazyLock::new(|| {
register_histogram_vec!(
"rpc_request_duration_seconds",
"Histogram of RPC request duration in seconds per endpoint",
&["endpoint"],
vec![0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1.0, 2.0, 5.0, 10.0]
)
.unwrap()
});
pub static HEALTH_CHECK_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
register_histogram_vec!(
"rpc_health_check_duration_seconds",
"Health check latency per endpoint",
&["endpoint"],
vec![0.1, 0.5, 1.0, 2.0, 5.0]
)
.unwrap()
});