use std::time::Instant;
pub const TELEMETRY_ORDERS_PLACED: &str = "orders.placed";
pub const TELEMETRY_ORDERS_CANCELLED: &str = "orders.cancelled";
pub const TELEMETRY_PLACE_ORDER_DURATION: &str = "place_order.duration";
pub const TELEMETRY_CANCEL_ORDER_DURATION: &str = "cancel_order.duration";
pub const TELEMETRY_BATCH_CANCEL_ORDER_DURATION: &str = "batch_cancel_orders.duration";
pub const TELEMETRY_QUERY_TX_DURATION: &str = "query_transaction.duration";
pub const TELEMETRY_WS_RECONNECTS: &str = "ws.reconnects";
pub const TELEMETRY_WS_RECEIVED: &str = "ws.received";
pub const TELEMETRY_WS_SENT: &str = "ws.sent";
pub const TELEMETRY_WS_SENT_DURATION: &str = "ws.sent.duration";
pub const TELEMETRY_DESC_ORDERS_PLACED: &str = "Orders opened with `place_order`";
pub const TELEMETRY_DESC_ORDERS_CANCELLED: &str = "Orders cancelled with `cancel_order`";
pub const TELEMETRY_DESC_PLACE_ORDER_DURATION: &str = "`place_order` duration in milliseconds";
pub const TELEMETRY_DESC_CANCEL_ORDER_DURATION: &str = "`cancel_order` duration in milliseconds";
pub const TELEMETRY_DESC_BATCH_CANCEL_ORDER_DURATION: &str =
"`batch_cancel_orders` duration in milliseconds";
pub const TELEMETRY_DESC_QUERY_TX_DURATION: &str = "`query_transaction` duration in milliseconds";
pub const TELEMETRY_DESC_WS_RECONNECTS: &str = "Reconnection attempts for Indexer Websocket feed";
pub const TELEMETRY_DESC_WS_RECEIVED: &str = "Messages received by Indexer Websocket feed";
pub const TELEMETRY_DESC_WS_SENT: &str = "Messages sent by Indexer Websocket feed";
pub const TELEMETRY_DESC_WS_SENT_DURATION: &str =
"Indexer Websocket feed messages, sending duration in milliseconds";
pub const TELEMETRY_LABEL_ADDRESS: &str = "address";
pub(crate) struct LatencyMetric {
name: &'static str,
start: Instant,
}
impl LatencyMetric {
pub(crate) fn new(name: &'static str) -> Self {
let start = Instant::now();
Self { name, start }
}
}
impl Drop for LatencyMetric {
fn drop(&mut self) {
let duration = self.start.elapsed();
let latency = (duration.as_secs() as f64) * (1_000_f64)
+ (duration.subsec_nanos() as f64) / (1_000_000_f64);
metrics::histogram!(self.name).record(latency);
}
}