<s> import time <EOL> import statsd <EOL> class PipedStatsd ( statsd . DogStatsd ) : <EOL> def time_deferred ( self , d , metric , tags , sample_rate = <NUM_LIT:1> ) : <EOL> def _time_and_passthrough ( result , start ) : <EOL> self . timing ( metric , time . time ( ) - start , tags = tags , sample_rate = sample_rate ) <EOL> return result <EOL> d . addBoth ( _time_and_passthrough , time . time ( ) ) <EOL> return d <EOL> class StatsdManager ( object ) : <EOL> """<STR_LIT>""" <EOL> _statsd_keywords = set ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def __init__ ( self ) : <EOL> self . _client_by_name = dict ( ) <EOL> def configure ( self , runtime_environment ) : <EOL> self . runtime_environment = runtime_environment <EOL> self . default_config = runtime_environment . get_configuration_value ( '<STR_LIT>' , dict ( host = '<STR_LIT:localhost>' , port = <NUM_LIT> ) ) <EOL> self . default = PipedStatsd ( ** self . default_config ) <EOL> def __getattr__ ( self , item ) : <EOL> if item in self . _statsd_keywords : <EOL> return getattr ( self . default , item ) <EOL> if item not in self . _client_by_name : <EOL> config = self . runtime_environment . get_configuration_value ( '<STR_LIT>' . format ( item ) , Ellipsis ) <EOL> if config is not Ellipsis : <EOL> self . _client_by_name [ item ] = PipedStatsd ( ** config ) <EOL> else : <EOL> self . _client_by_name [ item ] = self . default <EOL> return self . _client_by_name [ item ] </s>
