1use diem_metrics_core::{
9 register_histogram_vec, register_int_counter_vec, register_int_gauge_vec,
10 HistogramTimer, HistogramVec, IntCounterVec, IntGaugeVec,
11};
12use once_cell::sync::Lazy;
13
14pub static LATENCY: Lazy<HistogramVec> = Lazy::new(|| {
15 register_histogram_vec!(
16 "diem_safety_rules_latency",
17 "Time to perform an operation",
18 &["source", "field"]
19 )
20 .unwrap()
21});
22
23static QUERY_COUNTER: Lazy<IntCounterVec> = Lazy::new(|| {
24 register_int_counter_vec!(
25 "diem_safety_rules_queries",
26 "Outcome of calling into LSR",
27 &["method", "result"]
28 )
29 .unwrap()
30});
31
32static STATE_GAUGE: Lazy<IntGaugeVec> = Lazy::new(|| {
33 register_int_gauge_vec!(
34 "diem_safety_rules_state",
35 "Current internal state of LSR",
36 &["field"]
37 )
38 .unwrap()
39});
40
41pub fn increment_query(method: &str, result: &str) {
42 QUERY_COUNTER.with_label_values(&[method, result]).inc();
43}
44
45pub fn start_timer(source: &str, field: &str) -> HistogramTimer {
46 LATENCY.with_label_values(&[source, field]).start_timer()
47}
48
49pub fn set_state(field: &str, value: i64) {
50 STATE_GAUGE.with_label_values(&[field]).set(value);
51}