#NEWLINE# def send( self , data , sample_rate = 1 ) : #NEWLINE# #INDENT# '\n        Squirt the metrics over UDP\n        ' #NEWLINE# if self . prefix : #NEWLINE# #INDENT# data = dict ( ( ( '.' . join ( ( self . prefix , sample_rate ) ) , value ) for ( stat , value ) in data . items ( ) ) ) #NEWLINE# #UNINDENT# if ( sample_rate < 1 ) : #NEWLINE# #INDENT# if ( random . random ( ) > sample_rate ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# sampled_data = dict ( ( ( stat , ( '%s|@%s' % ( value , sample_rate ) ) ) for ( stat , value ) in data . items ( ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sampled_data = data #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# [ self . udp_sock . sendto ( bytes ( bytearray ( ( '%s:%s' % ( stat , value ) ) , 'utf-8' ) ) , self . addr ) for ( stat , value ) in sampled_data . items ( ) ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# self . log . exception ( 'unexpected error' )