<s> """<STR_LIT>""" <EOL> from diamond . metric import Metric <EOL> import diamond . collector <EOL> import glob <EOL> import re <EOL> import os <EOL> class HBaseCollector ( diamond . collector . Collector ) : <EOL> re_log = re . compile ( r'<STR_LIT>' ) <EOL> def get_default_config_help ( self ) : <EOL> config_help = super ( HBaseCollector , self ) . get_default_config_help ( ) <EOL> config_help . update ( { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> } ) <EOL> return config_help <EOL> def get_default_config ( self ) : <EOL> """<STR_LIT>""" <EOL> config = super ( HBaseCollector , self ) . get_default_config ( ) <EOL> config . update ( { <EOL> '<STR_LIT:path>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } ) <EOL> return config <EOL> def collect ( self ) : <EOL> for pattern in self . config [ '<STR_LIT>' ] : <EOL> for filename in glob . glob ( pattern ) : <EOL> self . collect_from ( filename ) <EOL> def collect_from ( self , filename ) : <EOL> if not os . access ( filename , os . R_OK ) : <EOL> self . log . error ( '<STR_LIT>' , filename ) <EOL> return False <EOL> fd = open ( filename , '<STR_LIT>' ) <EOL> for line in fd : <EOL> match = self . re_log . match ( line ) <EOL> if not match : <EOL> continue <EOL> metrics = { } <EOL> data = match . groupdict ( ) <EOL> for metric in data [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) : <EOL> metric = metric . strip ( ) <EOL> if '<STR_LIT:=>' in metric : <EOL> key , value = metric . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) <EOL> metrics [ key ] = value <EOL> for metric in metrics . keys ( ) : <EOL> try : <EOL> if data [ '<STR_LIT:name>' ] == '<STR_LIT>' : <EOL> path = self . get_metric_path ( '<STR_LIT:.>' . join ( [ <EOL> data [ '<STR_LIT:name>' ] , <EOL> metrics [ '<STR_LIT>' ] . replace ( '<STR_LIT:.>' , '<STR_LIT:_>' ) , <EOL> metrics [ '<STR_LIT>' ] . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) , <EOL> metric , ] ) ) <EOL> elif data [ '<STR_LIT:name>' ] == '<STR_LIT>' : <EOL> path = self . get_metric_path ( '<STR_LIT:.>' . join ( [ <EOL> data [ '<STR_LIT:name>' ] , <EOL> metrics [ '<STR_LIT>' ] . replace ( '<STR_LIT:.>' , '<STR_LIT:_>' ) , <EOL> metrics [ '<STR_LIT>' ] . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) , <EOL> metrics [ '<STR_LIT>' ] . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) , <EOL> metric , ] ) ) <EOL> elif data [ '<STR_LIT:name>' ] == '<STR_LIT>' : <EOL> if metric == '<STR_LIT:port>' : <EOL> continue <EOL> path = self . get_metric_path ( '<STR_LIT:.>' . join ( [ <EOL> data [ '<STR_LIT:name>' ] , <EOL> metrics [ '<STR_LIT>' ] . replace ( '<STR_LIT:.>' , '<STR_LIT:_>' ) , <EOL> metrics [ '<STR_LIT:port>' ] , <EOL> metric , ] ) ) <EOL> else : <EOL> path = self . get_metric_path ( '<STR_LIT:.>' . join ( [ <EOL> data [ '<STR_LIT:name>' ] , <EOL> metric , ] ) ) <EOL> value = float ( metrics [ metric ] ) <EOL> self . publish_metric ( Metric ( path , <EOL> value , <EOL> timestamp = int ( data [ '<STR_LIT>' ] ) / <NUM_LIT:1000> ) ) <EOL> except ValueError : <EOL> pass <EOL> fd . seek ( <NUM_LIT:0> ) <EOL> fd . truncate ( ) <EOL> fd . close ( ) </s>
