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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
use polkadot_node_subsystem_util::{
metrics,
metrics::{
prometheus,
prometheus::{Counter, CounterVec, Opts, PrometheusError, Registry, U64},
},
};
pub const SUCCEEDED: &'static str = "succeeded";
pub const FAILED: &'static str = "failed";
pub const NOT_FOUND: &'static str = "not-found";
#[derive(Clone, Default)]
pub struct Metrics(Option<MetricsInner>);
#[derive(Clone)]
struct MetricsInner {
fetched_chunks: CounterVec<U64>,
served_chunks: CounterVec<U64>,
fetched_povs: CounterVec<U64>,
served_povs: CounterVec<U64>,
retries: Counter<U64>,
}
impl Metrics {
pub fn new_dummy() -> Self {
Metrics(None)
}
pub fn on_fetch(&self, label: &'static str) {
if let Some(metrics) = &self.0 {
metrics.fetched_chunks.with_label_values(&[label]).inc()
}
}
pub fn on_served_chunk(&self, label: &'static str) {
if let Some(metrics) = &self.0 {
metrics.served_chunks.with_label_values(&[label]).inc()
}
}
pub fn on_fetched_pov(&self, label: &'static str) {
if let Some(metrics) = &self.0 {
metrics.fetched_povs.with_label_values(&[label]).inc()
}
}
pub fn on_served_pov(&self, label: &'static str) {
if let Some(metrics) = &self.0 {
metrics.served_povs.with_label_values(&[label]).inc()
}
}
pub fn on_retry(&self) {
if let Some(metrics) = &self.0 {
metrics.retries.inc()
}
}
}
impl metrics::Metrics for Metrics {
fn try_register(registry: &Registry) -> Result<Self, PrometheusError> {
let metrics = MetricsInner {
fetched_chunks: prometheus::register(
CounterVec::new(
Opts::new(
"polkadot_parachain_fetched_chunks_total",
"Total number of fetched chunks.",
),
&["success"]
)?,
registry,
)?,
served_chunks: prometheus::register(
CounterVec::new(
Opts::new(
"polkadot_parachain_served_chunks_total",
"Total number of chunks served by this backer.",
),
&["success"]
)?,
registry,
)?,
fetched_povs: prometheus::register(
CounterVec::new(
Opts::new(
"polkadot_parachain_fetched_povs_total",
"Total number of povs fetches by this backer.",
),
&["success"]
)?,
registry,
)?,
served_povs: prometheus::register(
CounterVec::new(
Opts::new(
"polkadot_parachain_served_povs_total",
"Total number of povs served by this backer.",
),
&["success"]
)?,
registry,
)?,
retries: prometheus::register(
Counter::new(
"polkadot_parachain_fetch_retries_total",
"Number of times we did not succeed in fetching a chunk and needed to try more backers.",
)?,
registry,
)?,
};
Ok(Metrics(Some(metrics)))
}
}