<s> """<STR_LIT>""" <EOL> import urllib2 <EOL> import diamond . collector <EOL> import datetime <EOL> class HttpCollector ( diamond . collector . Collector ) : <EOL> def get_default_config_help ( self ) : <EOL> config_help = super ( HttpCollector , self ) . get_default_config_help ( ) <EOL> config_help . update ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' , <EOL> } ) <EOL> return config_help <EOL> def get_default_config ( self ) : <EOL> default_config = super ( HttpCollector , self ) . get_default_config ( ) <EOL> default_config [ '<STR_LIT:path>' ] = '<STR_LIT:http>' <EOL> default_config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> default_config [ '<STR_LIT>' ] = [ '<STR_LIT>' ] <EOL> default_config [ '<STR_LIT>' ] = { '<STR_LIT>' : '<STR_LIT>' , } <EOL> return default_config <EOL> def collect ( self ) : <EOL> if self . config [ '<STR_LIT>' ] != "<STR_LIT>" : <EOL> self . config [ '<STR_LIT>' ] [ '<STR_LIT>' ] = self . config [ '<STR_LIT>' ] <EOL> for url in self . config [ '<STR_LIT>' ] : <EOL> self . log . debug ( "<STR_LIT>" , str ( url ) ) <EOL> req_start = datetime . datetime . now ( ) <EOL> req = urllib2 . Request ( url , headers = self . config [ '<STR_LIT>' ] ) <EOL> try : <EOL> handle = urllib2 . urlopen ( req ) <EOL> the_page = handle . read ( ) <EOL> req_end = datetime . datetime . now ( ) <EOL> req_time = req_end - req_start <EOL> metric_name = url . replace ( <EOL> '<STR_LIT:/>' , '<STR_LIT:_>' ) . replace ( <EOL> '<STR_LIT:.>' , '<STR_LIT:_>' ) . replace ( <EOL> '<STR_LIT:\\>' , '<STR_LIT>' ) . replace ( <EOL> '<STR_LIT::>' , '<STR_LIT>' ) <EOL> if metric_name == '<STR_LIT>' : <EOL> metric_name = "<STR_LIT:root>" <EOL> self . publish_gauge ( <EOL> metric_name + '<STR_LIT>' , <EOL> req_time . seconds * <NUM_LIT> + req_time . microseconds ) <EOL> self . publish_gauge ( <EOL> metric_name + '<STR_LIT>' , <EOL> len ( the_page ) ) <EOL> except IOError , e : <EOL> self . log . error ( "<STR_LIT>" , <EOL> self . config [ '<STR_LIT>' ] ) <EOL> except Exception , e : <EOL> self . log . error ( "<STR_LIT>" , e ) </s>
