@@ -31,6 +31,8 @@ pub struct Metrics {
31
31
connections_established : Family < ConnectionEstablishedLabels , Counter > ,
32
32
connections_closed : Family < ConnectionClosedLabels , Counter > ,
33
33
34
+ connections_denied : Family < AddressLabels , Counter > ,
35
+
34
36
new_listen_addr : Family < AddressLabels , Counter > ,
35
37
expired_listen_addr : Family < AddressLabels , Counter > ,
36
38
@@ -60,6 +62,13 @@ impl Metrics {
60
62
Box :: new ( connections_incoming_error. clone ( ) ) ,
61
63
) ;
62
64
65
+ let connections_denied = Family :: default ( ) ;
66
+ sub_registry. register (
67
+ "connections_denied" ,
68
+ "Number of denied connections" ,
69
+ Box :: new ( connections_denied. clone ( ) ) ,
70
+ ) ;
71
+
63
72
let new_listen_addr = Family :: default ( ) ;
64
73
sub_registry. register (
65
74
"new_listen_addr" ,
@@ -128,6 +137,7 @@ impl Metrics {
128
137
connections_incoming_error,
129
138
connections_established,
130
139
connections_closed,
140
+ connections_denied,
131
141
new_listen_addr,
132
142
expired_listen_addr,
133
143
listener_closed,
@@ -269,6 +279,13 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
269
279
libp2p_swarm:: SwarmEvent :: Dialing ( _) => {
270
280
self . dial_attempt . inc ( ) ;
271
281
}
282
+ libp2p_swarm:: SwarmEvent :: ConnectionDenied { endpoint, .. } => {
283
+ self . connections_denied
284
+ . get_or_create ( & AddressLabels {
285
+ protocols : protocol_stack:: as_string ( endpoint. get_remote_address ( ) ) ,
286
+ } )
287
+ . inc ( ) ;
288
+ }
272
289
}
273
290
}
274
291
}
0 commit comments