<s> """<STR_LIT>""" <EOL> import logging <EOL> from newrelic_plugin_agent . plugins import base <EOL> LOGGER = logging . getLogger ( __name__ ) <EOL> class Redis ( base . SocketStatsPlugin ) : <EOL> GUID = '<STR_LIT>' <EOL> DEFAULT_PORT = <NUM_LIT> <EOL> def add_datapoints ( self , stats ) : <EOL> """<STR_LIT>""" <EOL> self . add_gauge_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_gauge_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_gauge_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_gauge_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> if ( '<STR_LIT>' in self . derive_last_interval . keys ( ) and <EOL> '<STR_LIT>' in self . derive_last_interval . keys ( ) ) : <EOL> prev_hits = self . derive_last_interval [ '<STR_LIT>' ] <EOL> prev_misses = self . derive_last_interval [ '<STR_LIT>' ] <EOL> hits = stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) - prev_hits <EOL> misses = stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) - prev_misses <EOL> total = hits + misses <EOL> if total > <NUM_LIT:0> : <EOL> self . add_gauge_value ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:100> * hits / total ) <EOL> self . add_derive_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_derive_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_derive_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_derive_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_derive_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_derive_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_derive_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_derive_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_gauge_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_gauge_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_derive_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_derive_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_derive_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_derive_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_gauge_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> max_val = stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_gauge_value ( '<STR_LIT>' , '<STR_LIT>' , <EOL> stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> keys , expires = <NUM_LIT:0> , <NUM_LIT:0> <EOL> for db in range ( <NUM_LIT:0> , self . config . get ( '<STR_LIT>' , <NUM_LIT:16> ) ) : <EOL> db_stats = stats . get ( '<STR_LIT>' % db , dict ( ) ) <EOL> self . add_gauge_value ( '<STR_LIT>' % db , '<STR_LIT>' , <EOL> db_stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . add_gauge_value ( '<STR_LIT>' % db , '<STR_LIT>' , <EOL> db_stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> keys += db_stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> expires += db_stats . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> self . add_gauge_value ( '<STR_LIT>' , '<STR_LIT>' , keys ) <EOL> self . add_gauge_value ( '<STR_LIT>' , '<STR_LIT>' , expires ) <EOL> def connect ( self ) : <EOL> """<STR_LIT>""" <EOL> connection = super ( Redis , self ) . connect ( ) <EOL> if connection and self . config . get ( '<STR_LIT:password>' ) : <EOL> connection . send ( "<STR_LIT>" % <EOL> ( len ( self . config [ '<STR_LIT:password>' ] ) , <EOL> self . config [ '<STR_LIT:password>' ] ) ) <EOL> buffer_value = connection . recv ( self . SOCKET_RECV_MAX ) <EOL> if buffer_value == '<STR_LIT>' : <EOL> return connection <EOL> LOGGER . error ( '<STR_LIT>' , buffer_value [ <NUM_LIT:4> : ] . strip ( ) ) <EOL> return None <EOL> return connection <EOL> def fetch_data ( self , connection ) : <EOL> """<STR_LIT>""" <EOL> connection . send ( "<STR_LIT>" ) <EOL> buffer_value = connection . recv ( self . SOCKET_RECV_MAX ) <EOL> lines = buffer_value . split ( '<STR_LIT:\r\n>' ) <EOL> if lines [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] == '<STR_LIT:$>' : <EOL> byte_size = int ( lines [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] . strip ( ) ) <EOL> else : <EOL> return None <EOL> while len ( buffer_value ) < byte_size : <EOL> buffer_value += connection . recv ( self . SOCKET_RECV_MAX ) <EOL> lines = buffer_value . split ( '<STR_LIT:\r\n>' ) <EOL> values = dict ( ) <EOL> for line in lines : <EOL> if '<STR_LIT::>' in line : <EOL> key , value = line . strip ( ) . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> if key [ : <NUM_LIT:2> ] == '<STR_LIT>' : <EOL> values [ key ] = dict ( ) <EOL> subvalues = value . split ( '<STR_LIT:U+002C>' ) <EOL> for temp in subvalues : <EOL> subvalue = temp . split ( '<STR_LIT:=>' ) <EOL> value = subvalue [ - <NUM_LIT:1> ] <EOL> try : <EOL> values [ key ] [ subvalue [ <NUM_LIT:0> ] ] = int ( value ) <EOL> except ValueError : <EOL> try : <EOL> values [ key ] [ subvalue [ <NUM_LIT:0> ] ] = float ( value ) <EOL> except ValueError : <EOL> values [ key ] [ subvalue [ <NUM_LIT:0> ] ] = value <EOL> continue <EOL> try : <EOL> values [ key ] = int ( value ) <EOL> except ValueError : <EOL> try : <EOL> values [ key ] = float ( value ) <EOL> except ValueError : <EOL> values [ key ] = value <EOL> return values </s>
