<s> import socket <EOL> from httplib2 import Http , HttpLib2Error <EOL> import simplejson as json <EOL> from checks import AgentCheck <EOL> class Riak ( AgentCheck ) : <EOL> SERVICE_CHECK_NAME = '<STR_LIT>' <EOL> keys = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> stat_keys = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> def __init__ ( self , name , init_config , agentConfig , instances = None ) : <EOL> AgentCheck . __init__ ( self , name , init_config , agentConfig , instances ) <EOL> for k in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:100>" ] : <EOL> [ self . keys . append ( m + "<STR_LIT:_>" + k ) for m in self . stat_keys ] <EOL> self . prev_coord_redirs_total = - <NUM_LIT:1> <EOL> def check ( self , instance ) : <EOL> url = instance [ '<STR_LIT:url>' ] <EOL> default_timeout = self . init_config . get ( '<STR_LIT>' , <NUM_LIT:5> ) <EOL> timeout = float ( instance . get ( '<STR_LIT>' , default_timeout ) ) <EOL> tags = instance . get ( '<STR_LIT>' , [ ] ) <EOL> service_check_tags = [ '<STR_LIT>' % url ] <EOL> try : <EOL> h = Http ( timeout = timeout ) <EOL> resp , content = h . request ( url , "<STR_LIT:GET>" ) <EOL> except ( socket . timeout , socket . error , HttpLib2Error ) as e : <EOL> self . service_check ( self . SERVICE_CHECK_NAME , AgentCheck . CRITICAL , <EOL> message = "<STR_LIT>" % str ( e ) , <EOL> tags = service_check_tags ) <EOL> raise <EOL> if resp . status != <NUM_LIT:200> : <EOL> self . service_check ( self . SERVICE_CHECK_NAME , AgentCheck . CRITICAL , <EOL> tags = service_check_tags , <EOL> message = "<STR_LIT>" <EOL> "<STR_LIT>" % ( resp . status , content ) ) <EOL> stats = json . loads ( content ) <EOL> self . service_check ( <EOL> self . SERVICE_CHECK_NAME , AgentCheck . OK , tags = service_check_tags ) <EOL> [ self . gauge ( "<STR_LIT>" + k , stats [ k ] , tags = tags ) for k in self . keys if k in stats ] <EOL> coord_redirs_total = stats [ "<STR_LIT>" ] <EOL> if self . prev_coord_redirs_total > - <NUM_LIT:1> : <EOL> count = coord_redirs_total - self . prev_coord_redirs_total <EOL> self . gauge ( '<STR_LIT>' , count ) <EOL> self . prev_coord_redirs_total = coord_redirs_total </s>
