@@ -378,31 +378,31 @@ def check_network_latency(self, instance, agent_dc, main_tags):
378378 datacenters = self ._get_coord_datacenters (instance )
379379 for datacenter in datacenters :
380380 name = datacenter ['Datacenter' ]
381- if name ! = agent_dc :
382- # Not us, skip
383- continue
384- # Inter-datacenter
385- for other in datacenters :
386- other_name = other [ 'Datacenter' ]
387- if name == other_name :
388- # Ignore ourself
389- continue
390- latencies = []
391- for node_a in datacenter [ 'Coordinates' ]:
392- for node_b in other [ 'Coordinates' ]:
393- latencies . append ( distance ( node_a , node_b ))
394- latencies . sort ()
395- tags = main_tags + [ 'source_datacenter:{}' . format ( name ),
396- 'dest_datacenter:{}' . format ( other_name )]
397- n = len ( latencies )
398- half_n = int ( floor ( n / 2 ))
399- if n % 2 :
400- median = latencies [half_n ]
401- else :
402- median = ( latencies [ half_n - 1 ] + latencies [ half_n ]) / 2
403- self .gauge ('consul.net.dc.latency.min ' , latencies [0 ], hostname = '' , tags = tags )
404- self . gauge ( 'consul.net.dc.latency.median' , median , hostname = '' , tags = tags )
405- self . gauge ( 'consul.net.dc.latency.max' , latencies [ - 1 ], hostname = '' , tags = tags )
381+ if name = = agent_dc :
382+ # This is us, time to collect inter-datacenter data
383+ for other in datacenters :
384+ other_name = other [ 'Datacenter' ]
385+ if name == other_name :
386+ # Ignore ourself
387+ continue
388+ latencies = []
389+ for node_a in datacenter [ 'Coordinates' ]:
390+ for node_b in other [ 'Coordinates' ]:
391+ latencies . append ( distance ( node_a , node_b ))
392+ latencies . sort ()
393+ tags = main_tags + [ 'source_datacenter:{}' . format ( name ),
394+ 'dest_datacenter:{}' . format ( other_name )]
395+ n = len ( latencies )
396+ half_n = int ( floor ( n / 2 ))
397+ if n % 2 :
398+ median = latencies [ half_n ]
399+ else :
400+ median = ( latencies [half_n - 1 ] + latencies [ half_n ]) / 2
401+ self . gauge ( 'consul.net.dc.latency.min' , latencies [ 0 ], hostname = '' , tags = tags )
402+ self . gauge ( 'consul.net.dc.latency. median' , median , hostname = '' , tags = tags )
403+ self .gauge ('consul.net.dc.latency.max ' , latencies [- 1 ], hostname = '' , tags = tags )
404+ # We've found ourself, we can move on
405+ break
406406
407407 # Intra-datacenter
408408 nodes = self ._get_coord_nodes (instance )
0 commit comments