@@ -4,6 +4,12 @@ use torrust_tracker_primitives::DurationSinceUnixEpoch;
44
55use crate :: event:: { Event , UdpRequestKind , UdpResponseKind } ;
66use crate :: statistics:: repository:: Repository ;
7+ use crate :: statistics:: {
8+ UDP_TRACKER_SERVER_ERRORS_TOTAL , UDP_TRACKER_SERVER_PERFORMANCE_AVG_PROCESSING_TIME_NS ,
9+ UDP_TRACKER_SERVER_REQUESTS_ABORTED_TOTAL , UDP_TRACKER_SERVER_REQUESTS_ACCEPTED_TOTAL ,
10+ UDP_TRACKER_SERVER_REQUESTS_BANNED_TOTAL , UDP_TRACKER_SERVER_REQUESTS_RECEIVED_TOTAL ,
11+ UDP_TRACKER_SERVER_RESPONSES_SENT_TOTAL ,
12+ } ;
713
814/// # Panics
915///
@@ -19,7 +25,7 @@ pub async fn handle_event(event: Event, stats_repository: &Repository, now: Dura
1925 // Extendable metrics
2026 stats_repository
2127 . increase_counter (
22- & MetricName :: new ( "udp_tracker_server_requests_aborted_total" ) ,
28+ & MetricName :: new ( UDP_TRACKER_SERVER_REQUESTS_ABORTED_TOTAL ) ,
2329 & LabelSet :: from ( context) ,
2430 now,
2531 )
@@ -32,7 +38,7 @@ pub async fn handle_event(event: Event, stats_repository: &Repository, now: Dura
3238 // Extendable metrics
3339 stats_repository
3440 . increase_counter (
35- & MetricName :: new ( "udp_tracker_server_requests_banned_total" ) ,
41+ & MetricName :: new ( UDP_TRACKER_SERVER_REQUESTS_BANNED_TOTAL ) ,
3642 & LabelSet :: from ( context) ,
3743 now,
3844 )
@@ -52,7 +58,7 @@ pub async fn handle_event(event: Event, stats_repository: &Repository, now: Dura
5258 // Extendable metrics
5359 stats_repository
5460 . increase_counter (
55- & MetricName :: new ( "udp_tracker_server_requests_received_total" ) ,
61+ & MetricName :: new ( UDP_TRACKER_SERVER_REQUESTS_RECEIVED_TOTAL ) ,
5662 & LabelSet :: from ( context) ,
5763 now,
5864 )
@@ -94,11 +100,7 @@ pub async fn handle_event(event: Event, stats_repository: &Repository, now: Dura
94100 label_set. upsert ( LabelName :: new ( "kind" ) , LabelValue :: new ( & kind. to_string ( ) ) ) ;
95101
96102 stats_repository
97- . increase_counter (
98- & MetricName :: new ( "udp_tracker_server_requests_accepted_total" ) ,
99- & label_set,
100- now,
101- )
103+ . increase_counter ( & MetricName :: new ( UDP_TRACKER_SERVER_REQUESTS_ACCEPTED_TOTAL ) , & label_set, now)
102104 . await ;
103105 }
104106 Event :: UdpResponseSent {
@@ -124,10 +126,14 @@ pub async fn handle_event(event: Event, stats_repository: &Repository, now: Dura
124126 . await ;
125127
126128 // Extendable metrics
129+
130+ let mut label_set = LabelSet :: from ( context. clone ( ) ) ;
131+ label_set. upsert ( LabelName :: new ( "request_kind" ) , LabelValue :: new ( & req_kind. to_string ( ) ) ) ;
132+
127133 stats_repository
128134 . set_gauge (
129- & MetricName :: new ( "udp_tracker_server_performance_avg_connect_processing_time_ns" ) ,
130- & LabelSet :: from ( context . clone ( ) ) ,
135+ & MetricName :: new ( UDP_TRACKER_SERVER_PERFORMANCE_AVG_PROCESSING_TIME_NS ) ,
136+ & label_set ,
131137 new_avg,
132138 now,
133139 )
@@ -141,47 +147,57 @@ pub async fn handle_event(event: Event, stats_repository: &Repository, now: Dura
141147 . await ;
142148
143149 // Extendable metrics
150+
151+ let mut label_set = LabelSet :: from ( context. clone ( ) ) ;
152+ label_set. upsert ( LabelName :: new ( "request_kind" ) , LabelValue :: new ( & req_kind. to_string ( ) ) ) ;
153+
144154 stats_repository
145155 . set_gauge (
146- & MetricName :: new ( "udp_tracker_server_performance_avg_announce_processing_time_ns" ) ,
147- & LabelSet :: from ( context . clone ( ) ) ,
156+ & MetricName :: new ( UDP_TRACKER_SERVER_PERFORMANCE_AVG_PROCESSING_TIME_NS ) ,
157+ & label_set ,
148158 new_avg,
149159 now,
150160 )
151161 . await ;
152162
153- ( LabelValue :: new ( "ok" ) , LabelValue :: new ( & UdpRequestKind :: Connect . to_string ( ) ) )
163+ ( LabelValue :: new ( "ok" ) , LabelValue :: new ( & UdpRequestKind :: Announce . to_string ( ) ) )
154164 }
155165 UdpRequestKind :: Scrape => {
156166 let new_avg = stats_repository
157167 . recalculate_udp_avg_scrape_processing_time_ns ( req_processing_time)
158168 . await ;
159169
160170 // Extendable metrics
171+
172+ let mut label_set = LabelSet :: from ( context. clone ( ) ) ;
173+ label_set. upsert ( LabelName :: new ( "request_kind" ) , LabelValue :: new ( & req_kind. to_string ( ) ) ) ;
174+
161175 stats_repository
162176 . set_gauge (
163- & MetricName :: new ( "udp_tracker_server_performance_avg_scrape_processing_time_ns" ) ,
164- & LabelSet :: from ( context . clone ( ) ) ,
177+ & MetricName :: new ( UDP_TRACKER_SERVER_PERFORMANCE_AVG_PROCESSING_TIME_NS ) ,
178+ & label_set ,
165179 new_avg,
166180 now,
167181 )
168182 . await ;
169183
170- ( LabelValue :: new ( "ok" ) , LabelValue :: new ( & UdpRequestKind :: Connect . to_string ( ) ) )
184+ ( LabelValue :: new ( "ok" ) , LabelValue :: new ( & UdpRequestKind :: Scrape . to_string ( ) ) )
171185 }
172186 } ,
173- UdpResponseKind :: Error { opt_req_kind : _ } => ( LabelValue :: new ( "ok " ) , LabelValue :: ignore ( ) ) ,
187+ UdpResponseKind :: Error { opt_req_kind : _ } => ( LabelValue :: new ( "error " ) , LabelValue :: ignore ( ) ) ,
174188 } ;
175189
176190 // Extendable metrics
177191
178192 let mut label_set = LabelSet :: from ( context) ;
179193
194+ if result_label_value == LabelValue :: new ( "ok" ) {
195+ label_set. upsert ( LabelName :: new ( "request_kind" ) , kind_label_value) ;
196+ }
180197 label_set. upsert ( LabelName :: new ( "result" ) , result_label_value) ;
181- label_set. upsert ( LabelName :: new ( "kind" ) , kind_label_value) ;
182198
183199 stats_repository
184- . increase_counter ( & MetricName :: new ( "udp_tracker_server_responses_sent_total" ) , & label_set, now)
200+ . increase_counter ( & MetricName :: new ( UDP_TRACKER_SERVER_RESPONSES_SENT_TOTAL ) , & label_set, now)
185201 . await ;
186202 }
187203 Event :: UdpError { context } => {
@@ -198,7 +214,7 @@ pub async fn handle_event(event: Event, stats_repository: &Repository, now: Dura
198214 // Extendable metrics
199215 stats_repository
200216 . increase_counter (
201- & MetricName :: new ( "udp_tracker_server_errors_total" ) ,
217+ & MetricName :: new ( UDP_TRACKER_SERVER_ERRORS_TOTAL ) ,
202218 & LabelSet :: from ( context) ,
203219 now,
204220 )
0 commit comments