@@ -17,39 +17,39 @@ use crate::types::messages::{Request, Response};
17
17
/// and content validation.
18
18
#[ derive( Clone ) ]
19
19
pub struct OverlayMetrics {
20
- pub message_count : IntCounterVec ,
21
- pub utp_outcome_count : IntCounterVec ,
20
+ pub message_total : IntCounterVec ,
21
+ pub utp_outcome_total : IntCounterVec ,
22
22
pub utp_active_gauge : IntGaugeVec ,
23
- pub validation_count : IntCounterVec ,
23
+ pub validation_total : IntCounterVec ,
24
24
}
25
25
26
26
impl OverlayMetrics {
27
27
pub fn new ( registry : & Registry ) -> anyhow:: Result < Self > {
28
- let message_count = register_int_counter_vec_with_registry ! (
28
+ let message_total = register_int_counter_vec_with_registry ! (
29
29
opts!(
30
- "trin_message_count " ,
30
+ "trin_message_total " ,
31
31
"count all network messages sent and received"
32
32
) ,
33
33
& [ "protocol" , "direction" , "type" ] ,
34
34
registry
35
35
) ?;
36
- let utp_outcome_count = register_int_counter_vec_with_registry ! (
36
+ let utp_outcome_total = register_int_counter_vec_with_registry ! (
37
37
opts!(
38
- "trin_utp_outcome " ,
38
+ "trin_utp_outcome_total " ,
39
39
"track success rate for all utp transfers outbound and inbound"
40
40
) ,
41
41
& [ "protocol" , "direction" , "outcome" ] ,
42
42
registry
43
43
) ?;
44
44
let utp_active_gauge = register_int_gauge_vec_with_registry ! (
45
45
opts!(
46
- "trin_utp_active " ,
46
+ "trin_utp_active_streams " ,
47
47
"count all active utp transfers outbound and inbound"
48
48
) ,
49
49
& [ "protocol" , "direction" ] ,
50
50
registry
51
51
) ?;
52
- let validation_count = register_int_counter_vec_with_registry ! (
52
+ let validation_total = register_int_counter_vec_with_registry ! (
53
53
opts!(
54
54
"trin_validation_total" ,
55
55
"count all content validations successful and failed"
@@ -58,10 +58,10 @@ impl OverlayMetrics {
58
58
registry
59
59
) ?;
60
60
Ok ( Self {
61
- message_count ,
62
- utp_outcome_count ,
61
+ message_total ,
62
+ utp_outcome_total ,
63
63
utp_active_gauge,
64
- validation_count ,
64
+ validation_total ,
65
65
} )
66
66
}
67
67
}
@@ -73,53 +73,43 @@ pub struct OverlayMetricsReporter {
73
73
}
74
74
75
75
impl OverlayMetricsReporter {
76
- pub fn message_total ( & self , direction : & str , message_type : & str ) {
77
- let protocol: & str = & self . protocol . to_string ( ) ;
78
- self . overlay_metrics
79
- . message_count
80
- . with_label_values ( & [ protocol, direction, message_type] )
81
- . inc ( ) ;
82
- }
83
-
84
76
//
85
77
// Message Count
86
78
//
87
79
88
80
/// Returns the value of the given metric with the specified labels.
89
- pub fn message_count_by_labels (
81
+ fn message_total_by_labels (
90
82
& self ,
91
83
direction : MessageDirectionLabel ,
92
84
message_name : MessageLabel ,
93
85
) -> u64 {
94
- let protocol: & str = & self . protocol . to_string ( ) ;
95
- let labels: [ & str ; 3 ] = [ protocol, direction. into ( ) , message_name. into ( ) ] ;
86
+ let labels: [ & str ; 3 ] = [ & self . protocol , direction. into ( ) , message_name. into ( ) ] ;
96
87
self . overlay_metrics
97
- . message_count
88
+ . message_total
98
89
. with_label_values ( & labels)
99
90
. get ( )
100
91
}
101
92
102
93
pub fn report_outbound_request ( & self , request : & Request ) {
103
- self . increment_message_count ( MessageDirectionLabel :: Sent , request. into ( ) ) ;
94
+ self . increment_message_total ( MessageDirectionLabel :: Sent , request. into ( ) ) ;
104
95
}
105
96
106
97
pub fn report_inbound_request ( & self , request : & Request ) {
107
- self . increment_message_count ( MessageDirectionLabel :: Received , request. into ( ) ) ;
98
+ self . increment_message_total ( MessageDirectionLabel :: Received , request. into ( ) ) ;
108
99
}
109
100
110
101
pub fn report_outbound_response ( & self , response : & Response ) {
111
- self . increment_message_count ( MessageDirectionLabel :: Sent , response. into ( ) ) ;
102
+ self . increment_message_total ( MessageDirectionLabel :: Sent , response. into ( ) ) ;
112
103
}
113
104
114
105
pub fn report_inbound_response ( & self , response : & Response ) {
115
- self . increment_message_count ( MessageDirectionLabel :: Received , response. into ( ) ) ;
106
+ self . increment_message_total ( MessageDirectionLabel :: Received , response. into ( ) ) ;
116
107
}
117
108
118
- fn increment_message_count ( & self , direction : MessageDirectionLabel , message : MessageLabel ) {
119
- let protocol: & str = & self . protocol . to_string ( ) ;
120
- let labels: [ & str ; 3 ] = [ protocol, direction. into ( ) , message. into ( ) ] ;
109
+ fn increment_message_total ( & self , direction : MessageDirectionLabel , message : MessageLabel ) {
110
+ let labels: [ & str ; 3 ] = [ & self . protocol , direction. into ( ) , message. into ( ) ] ;
121
111
self . overlay_metrics
122
- . message_count
112
+ . message_total
123
113
. with_label_values ( & labels)
124
114
. inc ( ) ;
125
115
}
@@ -128,46 +118,41 @@ impl OverlayMetricsReporter {
128
118
// uTP metrics
129
119
//
130
120
131
- fn utp_active_count ( & self , direction : UtpDirectionLabel ) -> u64 {
132
- let protocol: & str = & self . protocol . to_string ( ) ;
133
- let labels: [ & str ; 2 ] = [ protocol, direction. into ( ) ] ;
121
+ fn utp_active_streams ( & self , direction : UtpDirectionLabel ) -> u64 {
122
+ let labels: [ & str ; 2 ] = [ & self . protocol , direction. into ( ) ] ;
134
123
self . overlay_metrics
135
124
. utp_active_gauge
136
125
. with_label_values ( & labels)
137
126
. get ( ) as u64
138
127
}
139
128
140
- fn utp_outcome_count ( & self , direction : UtpDirectionLabel , outcome : UtpOutcomeLabel ) -> u64 {
141
- let protocol: & str = & self . protocol . to_string ( ) ;
142
- let labels: [ & str ; 3 ] = [ protocol, direction. into ( ) , outcome. into ( ) ] ;
129
+ fn utp_outcome_total ( & self , direction : UtpDirectionLabel , outcome : UtpOutcomeLabel ) -> u64 {
130
+ let labels: [ & str ; 3 ] = [ & self . protocol , direction. into ( ) , outcome. into ( ) ] ;
143
131
self . overlay_metrics
144
- . utp_outcome_count
132
+ . utp_outcome_total
145
133
. with_label_values ( & labels)
146
134
. get ( )
147
135
}
148
136
149
137
pub fn report_utp_outcome ( & self , direction : UtpDirectionLabel , outcome : UtpOutcomeLabel ) {
150
- let protocol: & str = & self . protocol . to_string ( ) ;
151
- let labels: [ & str ; 3 ] = [ protocol, direction. into ( ) , outcome. into ( ) ] ;
138
+ let labels: [ & str ; 3 ] = [ & self . protocol , direction. into ( ) , outcome. into ( ) ] ;
152
139
self . overlay_metrics
153
- . utp_outcome_count
140
+ . utp_outcome_total
154
141
. with_label_values ( & labels)
155
142
. inc ( ) ;
156
143
self . report_utp_active_dec ( direction) ;
157
144
}
158
145
159
146
pub fn report_utp_active_inc ( & self , direction : UtpDirectionLabel ) {
160
- let protocol: & str = & self . protocol . to_string ( ) ;
161
- let labels: [ & str ; 2 ] = [ protocol, direction. into ( ) ] ;
147
+ let labels: [ & str ; 2 ] = [ & self . protocol , direction. into ( ) ] ;
162
148
self . overlay_metrics
163
149
. utp_active_gauge
164
150
. with_label_values ( & labels)
165
151
. inc ( ) ;
166
152
}
167
153
168
154
pub fn report_utp_active_dec ( & self , direction : UtpDirectionLabel ) {
169
- let protocol: & str = & self . protocol . to_string ( ) ;
170
- let labels: [ & str ; 2 ] = [ protocol, direction. into ( ) ] ;
155
+ let labels: [ & str ; 2 ] = [ & self . protocol , direction. into ( ) ] ;
171
156
self . overlay_metrics
172
157
. utp_active_gauge
173
158
. with_label_values ( & labels)
@@ -178,49 +163,47 @@ impl OverlayMetricsReporter {
178
163
// Validations
179
164
//
180
165
/// Returns the value of the given metric with the specified labels.
181
- pub fn validation_count_by_outcome ( & self , outcome : bool ) -> u64 {
182
- let protocol: & str = & self . protocol . to_string ( ) ;
166
+ fn validation_total_by_outcome ( & self , outcome : bool ) -> u64 {
183
167
let outcome = outcome. to_string ( ) ;
184
- let labels: [ & str ; 2 ] = [ protocol, outcome. as_str ( ) ] ;
168
+ let labels: [ & str ; 2 ] = [ & self . protocol , outcome. as_str ( ) ] ;
185
169
self . overlay_metrics
186
- . validation_count
170
+ . validation_total
187
171
. with_label_values ( & labels)
188
172
. get ( )
189
173
}
190
174
191
175
pub fn report_validation ( & self , success : bool ) {
192
- let protocol: & str = & self . protocol . to_string ( ) ;
193
176
let success = success. to_string ( ) ;
194
- let labels: [ & str ; 2 ] = [ protocol, success. as_str ( ) ] ;
177
+ let labels: [ & str ; 2 ] = [ & self . protocol , success. as_str ( ) ] ;
195
178
self . overlay_metrics
196
- . validation_count
179
+ . validation_total
197
180
. with_label_values ( & labels)
198
181
. inc ( ) ;
199
182
}
200
183
201
184
pub fn get_utp_summary ( & self ) -> String {
202
185
let inbound_success =
203
- self . utp_outcome_count ( UtpDirectionLabel :: Inbound , UtpOutcomeLabel :: Success ) ;
204
- let inbound_failed_connection = self . utp_outcome_count (
186
+ self . utp_outcome_total ( UtpDirectionLabel :: Inbound , UtpOutcomeLabel :: Success ) ;
187
+ let inbound_failed_connection = self . utp_outcome_total (
205
188
UtpDirectionLabel :: Inbound ,
206
189
UtpOutcomeLabel :: FailedConnection ,
207
190
) ;
208
191
let inbound_failed_data_tx =
209
- self . utp_outcome_count ( UtpDirectionLabel :: Inbound , UtpOutcomeLabel :: FailedDataTx ) ;
192
+ self . utp_outcome_total ( UtpDirectionLabel :: Inbound , UtpOutcomeLabel :: FailedDataTx ) ;
210
193
let inbound_failed_shutdown =
211
- self . utp_outcome_count ( UtpDirectionLabel :: Inbound , UtpOutcomeLabel :: FailedShutdown ) ;
194
+ self . utp_outcome_total ( UtpDirectionLabel :: Inbound , UtpOutcomeLabel :: FailedShutdown ) ;
212
195
let outbound_success =
213
- self . utp_outcome_count ( UtpDirectionLabel :: Outbound , UtpOutcomeLabel :: Success ) ;
214
- let outbound_failed_connection = self . utp_outcome_count (
196
+ self . utp_outcome_total ( UtpDirectionLabel :: Outbound , UtpOutcomeLabel :: Success ) ;
197
+ let outbound_failed_connection = self . utp_outcome_total (
215
198
UtpDirectionLabel :: Outbound ,
216
199
UtpOutcomeLabel :: FailedConnection ,
217
200
) ;
218
201
let outbound_failed_data_tx =
219
- self . utp_outcome_count ( UtpDirectionLabel :: Outbound , UtpOutcomeLabel :: FailedDataTx ) ;
202
+ self . utp_outcome_total ( UtpDirectionLabel :: Outbound , UtpOutcomeLabel :: FailedDataTx ) ;
220
203
let outbound_failed_shutdown =
221
- self . utp_outcome_count ( UtpDirectionLabel :: Outbound , UtpOutcomeLabel :: FailedShutdown ) ;
222
- let active_inbound = self . utp_active_count ( UtpDirectionLabel :: Inbound ) ;
223
- let active_outbound = self . utp_active_count ( UtpDirectionLabel :: Outbound ) ;
204
+ self . utp_outcome_total ( UtpDirectionLabel :: Outbound , UtpOutcomeLabel :: FailedShutdown ) ;
205
+ let active_inbound = self . utp_active_streams ( UtpDirectionLabel :: Inbound ) ;
206
+ let active_outbound = self . utp_active_streams ( UtpDirectionLabel :: Outbound ) ;
224
207
format ! (
225
208
"(in/out): active={} ({}/{}), success={} ({}/{}), failed={} ({}/{}) \
226
209
failed_connection={} ({}/{}), failed_data_tx={} ({}/{}), failed_shutdown={} ({}/{})",
@@ -253,14 +236,14 @@ impl OverlayMetricsReporter {
253
236
pub fn get_message_summary ( & self ) -> String {
254
237
// for every offer you made, how many accepts did you receive
255
238
// for every offer you received, how many accepts did you make
256
- let successful_validations = self . validation_count_by_outcome ( true ) ;
257
- let failed_validations = self . validation_count_by_outcome ( false ) ;
239
+ let successful_validations = self . validation_total_by_outcome ( true ) ;
240
+ let failed_validations = self . validation_total_by_outcome ( false ) ;
258
241
format ! (
259
242
"offers={}/{}, accepts={}/{}, validations={}/{}" ,
260
- self . message_count_by_labels ( MessageDirectionLabel :: Received , MessageLabel :: Accept ) ,
261
- self . message_count_by_labels ( MessageDirectionLabel :: Sent , MessageLabel :: Offer ) ,
262
- self . message_count_by_labels ( MessageDirectionLabel :: Sent , MessageLabel :: Accept ) ,
263
- self . message_count_by_labels ( MessageDirectionLabel :: Received , MessageLabel :: Offer ) ,
243
+ self . message_total_by_labels ( MessageDirectionLabel :: Received , MessageLabel :: Accept ) ,
244
+ self . message_total_by_labels ( MessageDirectionLabel :: Sent , MessageLabel :: Offer ) ,
245
+ self . message_total_by_labels ( MessageDirectionLabel :: Sent , MessageLabel :: Accept ) ,
246
+ self . message_total_by_labels ( MessageDirectionLabel :: Received , MessageLabel :: Offer ) ,
264
247
successful_validations,
265
248
successful_validations + failed_validations,
266
249
)
0 commit comments