use diem_metrics::{
register_histogram, register_histogram_vec, register_int_counter,
register_int_counter_vec, register_int_gauge, register_int_gauge_vec,
DurationHistogram, HistogramTimer, HistogramVec, IntCounter, IntCounterVec,
IntGauge, IntGaugeVec,
};
use once_cell::sync::Lazy;
use std::time::Duration;
pub const EXPIRATION_TIME_INDEX_LABEL: &str = "expiration";
pub const SYSTEM_TTL_INDEX_LABEL: &str = "system_ttl";
pub const TIMELINE_INDEX_LABEL: &str = "timeline";
pub const GET_BLOCK_STAGE_LABEL: &str = "get_block";
pub const COMMIT_ACCEPTED_LABEL: &str = "commit_accepted";
pub const COMMIT_REJECTED_LABEL: &str = "commit_rejected";
pub const GC_SYSTEM_TTL_LABEL: &str = "system_ttl";
pub const GC_CLIENT_EXP_LABEL: &str = "client_expiration";
pub const GET_BLOCK_LABEL: &str = "get_block";
pub const COMMIT_STATE_SYNC_LABEL: &str = "commit_accepted";
pub const COMMIT_CONSENSUS_LABEL: &str = "commit_rejected";
pub const REQUEST_FAIL_LABEL: &str = "fail";
pub const REQUEST_SUCCESS_LABEL: &str = "success";
pub const FETCH_SEQ_NUM_LABEL: &str = "storage_fetch";
pub const VM_VALIDATION_LABEL: &str = "vm_validation";
pub const CLIENT_LABEL: &str = "client";
pub const CLIENT_EVENT_LABEL: &str = "client_event";
pub const STATE_SYNC_EVENT_LABEL: &str = "state_sync";
pub const RECONFIG_EVENT_LABEL: &str = "reconfig";
pub const PEER_BROADCAST_EVENT_LABEL: &str = "peer_broadcast";
pub const SPAWN_LABEL: &str = "spawn";
pub const START_LABEL: &str = "start";
pub const BROADCAST_TXNS: &str = "broadcast_txns";
pub const ACK_TXNS: &str = "ack_txns";
pub const RECEIVED_LABEL: &str = "received";
pub const SENT_LABEL: &str = "sent";
static CORE_MEMPOOL_INDEX_SIZE: Lazy<IntGaugeVec> = Lazy::new(|| {
register_int_gauge_vec!(
"diem_core_mempool_index_size",
"Size of a core mempool index",
&["index"]
)
.unwrap()
});
pub fn core_mempool_index_size(label: &'static str, size: usize) {
CORE_MEMPOOL_INDEX_SIZE
.with_label_values(&[label])
.set(size as i64)
}
pub static CORE_MEMPOOL_REMOVED_TXNS: Lazy<IntCounter> = Lazy::new(|| {
register_int_counter!(
"diem_core_mempool_removed_txns_count",
"Number of txns removed from core mempool"
)
.unwrap()
});
pub static CORE_MEMPOOL_TXN_COMMIT_LATENCY: Lazy<HistogramVec> = Lazy::new(
|| {
register_histogram_vec!(
"diem_core_mempool_txn_commit_latency",
"Latency of txn reaching various stages in core mempool after insertion",
&["stage"]
)
.unwrap()
},
);
pub static CORE_MEMPOOL_GC_EVENT_COUNT: Lazy<IntCounterVec> = Lazy::new(|| {
register_int_counter_vec!(
"diem_core_mempool_gc_event_count",
"Number of times the periodic garbage-collection event occurs, regardless of how many txns were actually removed",
&["type"])
.unwrap()
});
static MEMPOOL_SERVICE_TXNS: Lazy<HistogramVec> = Lazy::new(|| {
register_histogram_vec!(
"diem_mempool_service_transactions",
"Number of transactions handled in one request/response between mempool and consensus/state sync",
&["type"]
)
.unwrap()
});
pub fn mempool_service_transactions(label: &'static str, num: usize) {
MEMPOOL_SERVICE_TXNS
.with_label_values(&[label])
.observe(num as f64)
}
static MEMPOOL_SERVICE_LATENCY: Lazy<HistogramVec> = Lazy::new(|| {
register_histogram_vec!(
"diem_mempool_service_latency_ms",
"Latency of mempool processing request from consensus/state sync",
&["type", "result"]
)
.unwrap()
});
pub fn mempool_service_latency(
label: &'static str, result: &str, duration: Duration,
) {
MEMPOOL_SERVICE_LATENCY
.with_label_values(&[label, result])
.observe(duration.as_secs_f64());
}
static SHARED_MEMPOOL_EVENTS: Lazy<IntCounterVec> = Lazy::new(|| {
register_int_counter_vec!(
"diem_shared_mempool_events",
"Number of network events received by shared mempool",
&["event"] )
.unwrap()
});
pub fn shared_mempool_event_inc(event: &'static str) {
SHARED_MEMPOOL_EVENTS.with_label_values(&[event]).inc();
}
static PROCESS_TXN_SUBMISSION_LATENCY: Lazy<HistogramVec> = Lazy::new(|| {
register_histogram_vec!(
"diem_shared_mempool_request_latency",
"Latency of mempool processing txn submission requests",
&["network", "sender"] )
.unwrap()
});
pub fn process_txn_submit_latency_timer(
network: &str, sender: &str,
) -> HistogramTimer {
PROCESS_TXN_SUBMISSION_LATENCY
.with_label_values(&[network, sender])
.start_timer()
}
pub static PROCESS_TXN_BREAKDOWN_LATENCY: Lazy<HistogramVec> =
Lazy::new(|| {
register_histogram_vec!(
"diem_mempool_process_txn_breakdown_latency",
"Latency of different stages of processing txns in mempool",
&["portion"]
)
.unwrap()
});
static TASK_SPAWN_LATENCY: Lazy<HistogramVec> = Lazy::new(|| {
register_histogram_vec!(
"diem_mempool_bounded_executor_spawn_latency",
"Time it takes for mempool's coordinator to spawn async tasks",
&["task", "stage"]
)
.unwrap()
});
pub fn task_spawn_latency_timer(
task: &'static str, stage: &'static str,
) -> HistogramTimer {
TASK_SPAWN_LATENCY
.with_label_values(&[task, stage])
.start_timer()
}
static NETWORK_SEND_FAIL: Lazy<IntCounterVec> = Lazy::new(|| {
register_int_counter_vec!(
"diem_mempool_network_send_fail_count",
"Number of times mempool network send failure occurs",
&["type"]
)
.unwrap()
});
pub fn network_send_fail_inc(label: &'static str) {
NETWORK_SEND_FAIL.with_label_values(&[label]).inc();
}
pub static CLIENT_CALLBACK_FAIL: Lazy<IntCounter> = Lazy::new(|| {
register_int_counter!(
"diem_mempool_json_rpc_callback_fail_count",
"Number of times callback to JSON RPC failed in mempool"
)
.unwrap()
});
static UPSTREAM_NETWORK: Lazy<IntGauge> = Lazy::new(|| {
register_int_gauge!(
"diem_mempool_upstream_network",
"The preference of the network mempool is broadcasting to"
)
.unwrap()
});
pub fn upstream_network(network: usize) { UPSTREAM_NETWORK.set(network as i64) }
pub static MAIN_LOOP: Lazy<DurationHistogram> = Lazy::new(|| {
DurationHistogram::new(
register_histogram!(
"diem_mempool_main_loop",
"Duration of the each run of the event loop"
)
.unwrap(),
)
});