#[cfg(feature = "metrics")]
use metrics::{counter, gauge};
pub const CONNECTIONS_ACTIVE: &str = "wireframe_connections_active";
pub const FRAMES_PROCESSED: &str = "wireframe_frames_processed_total";
pub const ERRORS_TOTAL: &str = "wireframe_errors_total";
pub const CONNECTION_PANICS: &str = "wireframe_connection_panics_total";
pub const CODEC_ERRORS: &str = "wireframe_codec_errors_total";
#[derive(Clone, Copy)]
pub enum Direction {
Inbound,
Outbound,
}
impl Direction {
fn as_str(self) -> &'static str {
match self {
Direction::Inbound => "inbound",
Direction::Outbound => "outbound",
}
}
}
#[cfg(feature = "metrics")]
pub fn inc_connections() { gauge!(CONNECTIONS_ACTIVE).increment(1.0); }
#[cfg(not(feature = "metrics"))]
pub fn inc_connections() {}
#[cfg(feature = "metrics")]
pub fn dec_connections() { gauge!(CONNECTIONS_ACTIVE).decrement(1.0); }
#[cfg(not(feature = "metrics"))]
pub fn dec_connections() {}
#[cfg(feature = "metrics")]
pub fn inc_frames(direction: Direction) {
counter!(FRAMES_PROCESSED, "direction" => direction.as_str()).increment(1);
}
#[cfg(not(feature = "metrics"))]
pub fn inc_frames(_direction: Direction) {}
#[cfg(feature = "metrics")]
pub fn inc_deser_errors() { counter!(ERRORS_TOTAL, "kind" => "deserialization").increment(1); }
#[cfg(not(feature = "metrics"))]
pub fn inc_deser_errors() {}
#[cfg(feature = "metrics")]
pub fn inc_handler_errors() { counter!(ERRORS_TOTAL, "kind" => "handler").increment(1); }
#[cfg(not(feature = "metrics"))]
pub fn inc_handler_errors() {}
#[cfg(feature = "metrics")]
pub fn inc_connection_panics() { counter!(CONNECTION_PANICS).increment(1); }
#[cfg(not(feature = "metrics"))]
pub fn inc_connection_panics() {}
#[cfg(feature = "metrics")]
pub fn inc_codec_error(error_type: &'static str, recovery_policy: &'static str) {
counter!(
CODEC_ERRORS,
"error_type" => error_type,
"recovery_policy" => recovery_policy
)
.increment(1);
}
#[cfg(not(feature = "metrics"))]
pub fn inc_codec_error(_error_type: &'static str, _recovery_policy: &'static str) {}