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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
use core::fmt;
use opentelemetry::{
global,
metrics::{Counter, UpDownCounter},
KeyValue,
};
use opentelemetry_prometheus::PrometheusExporter;
use ibc::ics24_host::identifier::{ChainId, ChannelId, ClientId, PortId};
use prometheus::proto::MetricFamily;
#[derive(Copy, Clone, Debug)]
pub enum WorkerType {
Client,
Connection,
Channel,
Packet,
}
impl fmt::Display for WorkerType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Client => write!(f, "client"),
Self::Connection => write!(f, "connection"),
Self::Channel => write!(f, "channel"),
Self::Packet => write!(f, "packet"),
}
}
}
#[derive(Debug)]
pub struct TelemetryState {
exporter: PrometheusExporter,
workers: UpDownCounter<i64>,
ibc_client_updates: Counter<u64>,
ibc_client_misbehaviours: Counter<u64>,
receive_packets: Counter<u64>,
acknowledgment_packets: Counter<u64>,
timeout_packets: Counter<u64>,
}
impl TelemetryState {
pub fn gather(&self) -> Vec<MetricFamily> {
self.exporter.registry().gather()
}
pub fn worker(&self, worker_type: WorkerType, count: i64) {
let labels = &[KeyValue::new("type", worker_type.to_string())];
self.workers.add(count, labels);
}
pub fn ibc_client_update(&self, chain: &ChainId, client: &ClientId, count: u64) {
let labels = &[
KeyValue::new("chain", chain.to_string()),
KeyValue::new("client", client.to_string()),
];
self.ibc_client_updates.add(count, labels);
}
pub fn ibc_client_misbehaviour(&self, chain: &ChainId, client: &ClientId, count: u64) {
let labels = &[
KeyValue::new("chain", chain.to_string()),
KeyValue::new("client", client.to_string()),
];
self.ibc_client_misbehaviours.add(count, labels);
}
pub fn ibc_receive_packets(
&self,
src_chain: &ChainId,
src_channel: &ChannelId,
src_port: &PortId,
count: u64,
) {
let labels = &[
KeyValue::new("src_chain", src_chain.to_string()),
KeyValue::new("src_channel", src_channel.to_string()),
KeyValue::new("src_port", src_port.to_string()),
];
self.receive_packets.add(count, labels);
}
pub fn ibc_acknowledgment_packets(
&self,
src_chain: &ChainId,
src_channel: &ChannelId,
src_port: &PortId,
count: u64,
) {
let labels = &[
KeyValue::new("src_chain", src_chain.to_string()),
KeyValue::new("src_channel", src_channel.to_string()),
KeyValue::new("src_port", src_port.to_string()),
];
self.acknowledgment_packets.add(count, labels);
}
pub fn ibc_timeout_packets(
&self,
src_chain: &ChainId,
src_channel: &ChannelId,
src_port: &PortId,
count: u64,
) {
let labels = &[
KeyValue::new("src_chain", src_chain.to_string()),
KeyValue::new("src_channel", src_channel.to_string()),
KeyValue::new("src_port", src_port.to_string()),
];
self.timeout_packets.add(count, labels);
}
}
impl Default for TelemetryState {
fn default() -> Self {
let exporter = opentelemetry_prometheus::exporter().init();
let meter = global::meter("hermes");
Self {
exporter,
workers: meter
.i64_up_down_counter("workers")
.with_description("Number of workers per object")
.init(),
ibc_client_updates: meter
.u64_counter("ibc_client_updates")
.with_description("Number of client updates performed per client")
.init(),
ibc_client_misbehaviours: meter
.u64_counter("ibc_client_misbehaviours")
.with_description("Number of misbehaviours detected per client")
.init(),
receive_packets: meter
.u64_counter("ibc_receive_packets")
.with_description("Number of receive packets relayed per channel")
.init(),
acknowledgment_packets: meter
.u64_counter("ibc_acknowledgment_packets")
.with_description("Number of acknowledgment packets relayed per channel")
.init(),
timeout_packets: meter
.u64_counter("ibc_timeout_packets")
.with_description("Number of timeout packets relayed per channel")
.init(),
}
}
}