<s> from __future__ import unicode_literals <EOL> from goblin . _compat import print_ <EOL> from goblin . metrics . base import BaseMetricsReporter <EOL> import newrelic <EOL> class NewRelicReporter ( BaseMetricsReporter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , config_file , environment = None , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . agent = newrelic . agent <EOL> self . agent . initialize ( config_file , environment = environment ) <EOL> super ( NewRelicReporter , self ) . __init__ ( * args , ** kwargs ) <EOL> def convert_metric_name ( self , key , metric ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' + key . replace ( '<STR_LIT:.>' , '<STR_LIT:/>' ) + '<STR_LIT:/>' + metric <EOL> def send_metrics ( self ) : <EOL> """<STR_LIT>""" <EOL> metrics = self . get_metrics ( ) <EOL> if not metrics : <EOL> return <EOL> for mkey , metric in metrics . items ( ) : <EOL> for mname , mval in metric . items ( ) : <EOL> try : <EOL> self . agent . record_custom_metric ( self . convert_metric_name ( mkey , mname ) , mval , None ) <EOL> except Exception as e : <EOL> print_ ( e ) </s>
