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 lazy_static::lazy_static;
use prometheus::*;
use std::sync::Mutex;
lazy_static! {
pub static ref MULTILEVEL_LEVEL_ELAPSED: IntCounterVec = IntCounterVec::new(
new_opts(
"multilevel_level_elapsed",
"elapsed time of each level in the multilevel task queue"
),
&["name", "level"]
)
.unwrap();
pub static ref MULTILEVEL_LEVEL0_CHANCE: GaugeVec = GaugeVec::new(
new_opts(
"multilevel_level0_chance",
"the chance that a level 0 task is scheduled to run"
),
&["name"]
)
.unwrap();
static ref NAMESPACE: Mutex<Option<String>> = Mutex::new(None);
}
pub fn set_namespace(s: Option<impl Into<String>>) {
*NAMESPACE.lock().unwrap() = s.map(Into::into)
}
fn new_opts(name: &str, help: &str) -> Opts {
let mut opts = Opts::new(name, help);
if let Some(ref namespace) = *NAMESPACE.lock().unwrap() {
opts = opts.namespace(namespace);
}
opts
}