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
48
49
50
51
52
53
use lazy_static::lazy_static;
use prometheus::*;
#[cfg(target_os = "linux")]
mod threads_linux;
#[cfg(target_os = "linux")]
pub use self::threads_linux::{cpu_total, get_thread_ids, monitor_threads, ThreadInfoStatistics};
#[cfg(target_os = "linux")]
mod process_linux;
#[cfg(target_os = "linux")]
pub use self::process_linux::monitor_process;
#[cfg(not(target_os = "linux"))]
mod threads_dummy;
#[cfg(not(target_os = "linux"))]
pub use self::threads_dummy::{monitor_threads, ThreadInfoStatistics};
#[cfg(not(target_os = "linux"))]
mod process_dummy;
#[cfg(not(target_os = "linux"))]
pub use self::process_dummy::monitor_process;
pub use self::allocator_metrics::monitor_allocator_stats;
pub mod allocator_metrics;
pub use self::metrics_reader::HistogramReader;
mod metrics_reader;
pub fn dump() -> String {
let mut buffer = vec![];
let encoder = TextEncoder::new();
let metric_families = prometheus::gather();
for mf in metric_families {
if let Err(e) = encoder.encode(&[mf], &mut buffer) {
warn!("prometheus encoding error"; "err" => ?e);
}
}
String::from_utf8(buffer).unwrap()
}
lazy_static! {
pub static ref CRITICAL_ERROR: IntCounterVec = register_int_counter_vec!(
"tikv_critical_error_total",
"Counter of critical error.",
&["type"]
)
.unwrap();
}