#NEWLINE# def collect( self ) : #NEWLINE# #INDENT# for key in self . config . keys ( ) : #NEWLINE# #INDENT# if ( ping [ : 7 ] == 'target_' ) : #NEWLINE# #INDENT# host = self . config [ key ] #NEWLINE# metric_name = host . replace ( '.' , '_' ) #NEWLINE# ping = self . run_command ( [ '-nq' , '-c 1' , host ] ) #NEWLINE# ping = ping [ 0 ] . strip ( ) . split ( '\n' ) [ ( - 1 ) ] #NEWLINE# if ping . startswith ( 'rtt' ) : #NEWLINE# #INDENT# ping = ping . split ( ) [ 3 ] . split ( '/' ) [ 0 ] #NEWLINE# metric_value = float ( ping ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ping . startswith ( 'round-trip ' ) : #NEWLINE# #INDENT# ping = ping . split ( ) [ 3 ] . split ( '/' ) [ 0 ] #NEWLINE# metric_value = float ( ping ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# metric_value = 10000 #NEWLINE# #UNINDENT# #UNINDENT# self . publish ( metric_name , metric_value , precision = 3 )