@@ -854,6 +854,8 @@ struct Metrics {
854854 // This list is ordered alphabetically
855855 connections_closed_total : CounterVec < U64 > ,
856856 connections_opened_total : CounterVec < U64 > ,
857+ distinct_peers_connections_closed_total : CounterVec < U64 > ,
858+ distinct_peers_connections_opened_total : CounterVec < U64 > ,
857859 import_queue_blocks_submitted : Counter < U64 > ,
858860 import_queue_finality_proofs_submitted : Counter < U64 > ,
859861 import_queue_justifications_submitted : Counter < U64 > ,
@@ -889,16 +891,30 @@ impl Metrics {
889891 connections_closed_total : register ( CounterVec :: new (
890892 Opts :: new (
891893 "sub_libp2p_connections_closed_total" ,
892- "Total number of connections closed, by direction, reason and by being the first or not "
894+ "Total number of connections closed, by direction and reason "
893895 ) ,
894- & [ "direction" , "reason" , "was_first" ]
896+ & [ "direction" , "reason" ]
895897 ) ?, registry) ?,
896898 connections_opened_total : register ( CounterVec :: new (
897899 Opts :: new (
898900 "sub_libp2p_connections_opened_total" ,
899- "Total number of connections opened by direction and by being the first or not "
901+ "Total number of connections opened by direction"
900902 ) ,
901- & [ "direction" , "is_first" ]
903+ & [ "direction" ]
904+ ) ?, registry) ?,
905+ distinct_peers_connections_closed_total : register ( CounterVec :: new (
906+ Opts :: new (
907+ "sub_libp2p_distinct_peers_connections_closed_total" ,
908+ "Total number of connections closed with distinct peers, by direction and reason"
909+ ) ,
910+ & [ "direction" , "reason" ]
911+ ) ?, registry) ?,
912+ distinct_peers_connections_opened_total : register ( CounterVec :: new (
913+ Opts :: new (
914+ "sub_libp2p_distinct_peers_connections_opened_total" ,
915+ "Total number of connections opened with distinct peers by direction"
916+ ) ,
917+ & [ "direction" ]
902918 ) ?, registry) ?,
903919 import_queue_blocks_submitted : register ( Counter :: new (
904920 "import_queue_blocks_submitted" ,
@@ -1222,9 +1238,12 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
12221238 ConnectedPoint :: Dialer { .. } => "out" ,
12231239 ConnectedPoint :: Listener { .. } => "in" ,
12241240 } ;
1225- let is_first = if num_established. get ( ) == 1 { "true" } else { "false" } ;
12261241
1227- metrics. connections_opened_total . with_label_values ( & [ direction, is_first] ) . inc ( ) ;
1242+ metrics. connections_opened_total . with_label_values ( & [ direction] ) . inc ( ) ;
1243+
1244+ if num_established. get ( ) == 1 {
1245+ metrics. distinct_peers_connections_opened_total . with_label_values ( & [ direction] ) . inc ( ) ;
1246+ }
12281247 }
12291248 } ,
12301249 Poll :: Ready ( SwarmEvent :: ConnectionClosed { peer_id, cause, endpoint, num_established } ) => {
@@ -1247,10 +1266,12 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
12471266 ConnectionError :: Handler ( NodeHandlerWrapperError :: KeepAliveTimeout ) => "keep-alive-timeout" ,
12481267 } ;
12491268
1250- // `num_established` represents the number of *remaining* connections.
1251- let was_first = if num_established == 0 { "true" } else { "false" } ;
1269+ metrics. connections_closed_total . with_label_values ( & [ direction, reason] ) . inc ( ) ;
12521270
1253- metrics. connections_closed_total . with_label_values ( & [ direction, reason, was_first] ) . inc ( ) ;
1271+ // `num_established` represents the number of *remaining* connections.
1272+ if num_established == 0 {
1273+ metrics. distinct_peers_connections_closed_total . with_label_values ( & [ direction, reason] ) . inc ( ) ;
1274+ }
12541275 }
12551276 } ,
12561277 Poll :: Ready ( SwarmEvent :: NewListenAddr ( addr) ) => {
0 commit comments