@@ -31,6 +31,8 @@ pub struct Metrics {
3131 connections_established : Family < ConnectionEstablishedLabels , Counter > ,
3232 connections_closed : Family < ConnectionClosedLabels , Counter > ,
3333
34+ connections_denied : Family < AddressLabels , Counter > ,
35+
3436 new_listen_addr : Family < AddressLabels , Counter > ,
3537 expired_listen_addr : Family < AddressLabels , Counter > ,
3638
@@ -60,6 +62,13 @@ impl Metrics {
6062 Box :: new ( connections_incoming_error. clone ( ) ) ,
6163 ) ;
6264
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+
6372 let new_listen_addr = Family :: default ( ) ;
6473 sub_registry. register (
6574 "new_listen_addr" ,
@@ -128,6 +137,7 @@ impl Metrics {
128137 connections_incoming_error,
129138 connections_established,
130139 connections_closed,
140+ connections_denied,
131141 new_listen_addr,
132142 expired_listen_addr,
133143 listener_closed,
@@ -269,6 +279,13 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
269279 libp2p_swarm:: SwarmEvent :: Dialing ( _) => {
270280 self . dial_attempt . inc ( ) ;
271281 }
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+ }
272289 }
273290 }
274291}
0 commit comments