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