<s> from txstatsd . metrics . countermetric import CounterMetric <EOL> from txstatsd . metrics . timermetric import TimerMetric <EOL> from txstatsd . metrics . metrics import Metrics <EOL> class ExtendedMetrics ( Metrics ) : <EOL> def __init__ ( self , connection = None , namespace = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> super ( ExtendedMetrics , self ) . __init__ ( connection , namespace ) <EOL> def increment ( self , name , value = <NUM_LIT:1> , sample_rate = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> name = self . fully_qualify_name ( name ) <EOL> if not name in self . _metrics : <EOL> metric = CounterMetric ( self . connection , <EOL> name , <EOL> sample_rate ) <EOL> self . _metrics [ name ] = metric <EOL> self . _metrics [ name ] . increment ( value ) <EOL> def decrement ( self , name , value = <NUM_LIT:1> , sample_rate = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> name = self . fully_qualify_name ( name ) <EOL> if not name in self . _metrics : <EOL> metric = CounterMetric ( self . connection , <EOL> name , <EOL> sample_rate ) <EOL> self . _metrics [ name ] = metric <EOL> self . _metrics [ name ] . decrement ( value ) <EOL> def timing ( self , name , duration = None , sample_rate = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if duration is None : <EOL> duration = self . calculate_duration ( ) <EOL> name = self . fully_qualify_name ( name ) <EOL> if not name in self . _metrics : <EOL> metric = TimerMetric ( self . connection , <EOL> name , <EOL> sample_rate ) <EOL> self . _metrics [ name ] = metric <EOL> self . _metrics [ name ] . mark ( duration ) </s>
