<s> """<STR_LIT>""" <EOL> try : <EOL> import json <EOL> except ImportError : <EOL> import simplejson as json <EOL> import urllib2 <EOL> import diamond . collector <EOL> class SidekiqWebCollector ( diamond . collector . Collector ) : <EOL> def get_default_config_help ( self ) : <EOL> config_help = super ( SidekiqWebCollector , <EOL> self ) . get_default_config_help ( ) <EOL> config_help . update ( { <EOL> } ) <EOL> return config_help <EOL> def get_default_config ( self ) : <EOL> """<STR_LIT>""" <EOL> config = super ( SidekiqWebCollector , self ) . get_default_config ( ) <EOL> config . update ( { <EOL> '<STR_LIT:host>' : '<STR_LIT:localhost>' , <EOL> '<STR_LIT:port>' : <NUM_LIT> , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } ) <EOL> return config <EOL> def collect ( self ) : <EOL> try : <EOL> response = urllib2 . urlopen ( "<STR_LIT>" % ( <EOL> self . config [ '<STR_LIT:host>' ] , int ( self . config [ '<STR_LIT:port>' ] ) ) ) <EOL> except Exception , e : <EOL> self . log . error ( '<STR_LIT>' , e ) <EOL> return { } <EOL> try : <EOL> j = json . loads ( response . read ( ) ) <EOL> except Exception , e : <EOL> self . log . error ( '<STR_LIT>' , e ) <EOL> return { } <EOL> for k in j : <EOL> for item , value in j [ k ] . items ( ) : <EOL> if isinstance ( value , ( str , unicode ) ) and '<STR_LIT:M>' in value : <EOL> value = float ( value . replace ( '<STR_LIT:M>' , '<STR_LIT>' ) ) <EOL> for unit in self . config [ '<STR_LIT>' ] : <EOL> unit_value = diamond . convertor . binary . convert ( <EOL> value = value , <EOL> oldUnit = '<STR_LIT>' , <EOL> newUnit = unit ) <EOL> self . publish ( "<STR_LIT>" % ( k , item , unit ) , unit_value ) <EOL> else : <EOL> self . publish ( "<STR_LIT>" % ( k , item ) , value ) </s>
