(self, nick, host, port, unix_socket, auth)
Collect metrics from a single Redis instance

:param str nick: nickname of redis instance
:param str host: redis host
:param int port: redis port
:param str unix_socket: unix socket, if applicable
:param str auth: authentication password
Collect metrics from a single Redis instance
Collect metrics from a single Redis instance
def collect_instance(self, nick, host, port, unix_socket, auth):
        """Collect metrics from a single Redis instance

:param str nick: nickname of redis instance
:param str host: redis host
:param int port: redis port
:param str unix_socket: unix socket, if applicable
:param str auth: authentication password

        """

        # Connect to redis and get the info
        info = self._get_info(host, port, unix_socket, auth)
        if info is None:
            return

        # The structure should include the port for multiple instances per
        # server
        data = dict()

        # Role needs to be handled outside the the _KEYS dict
        # since the value is a string, not a int / float
        # Also, master_sync_in_progress is only available if the
        # redis instance is a slave, so default it here so that
        # the metric is cleared if the instance flips from slave
        # to master
        if 'role' in info:
            if info['role'] == "master":
                data['replication.master'] = 1
                data['replication.master_sync_in_progress'] = 0
            else:
                data['replication.master'] = 0

        # Connect to redis and get the maxmemory config value
        # Then calculate the % maxmemory of memory used
        maxmemory_config = self._get_config(host, port, unix_socket, auth,
                                            'maxmemory')
        if maxmemory_config and 'maxmemory' in maxmemory_config.keys():
            maxmemory = float(maxmemory_config['maxmemory'])

            # Only report % used if maxmemory is a non zero value
            if maxmemory == 0:
                maxmemory_percent = 0.0
            else:
                maxmemory_percent = info['used_memory'] / maxmemory * 100
                maxmemory_percent = round(maxmemory_percent, 2)
            data['memory.used_percent'] = float("%.2f" % maxmemory_percent)

        # Iterate over the top level keys
        for key in self._KEYS:
            if self._KEYS[key] in info:
                data[key] = info[self._KEYS[key]]

        # Iterate over renamed keys for 2.6 support
        for key in self._RENAMED_KEYS:
            if self._RENAMED_KEYS[key] in info:
                data[key] = info[self._RENAMED_KEYS[key]]

        # Look for databaase speific stats
        for dbnum in range(0, int(self.config.get('databases',
                                                  self._DATABASE_COUNT))):
            db = 'db%i' % dbnum
            if db in info:
                for key in info[db]:
                    data['%s.%s' % (db, key)] = info[db][key]

        # Time since last save
        for key in ['last_save_time', 'rdb_last_save_time']:
            if key in info:
                data['last_save.time_since'] = int(time.time()) - info[key]

        # Publish the data to graphite
        for key in data:
            self.publish(self._publish_key(nick, key),
                         data[key],
                         precision=self._precision(data[key]),
                         metric_type='GAUGE')
def collect_instance ( self , nick , host , port , unix_socket , auth ) : # Connect to redis and get the info info = self . _get_info ( host , port , unix_socket , auth ) if info is None : return # The structure should include the port for multiple instances per # server data = dict ( ) # Role needs to be handled outside the the _KEYS dict # since the value is a string, not a int / float # Also, master_sync_in_progress is only available if the # redis instance is a slave, so default it here so that # the metric is cleared if the instance flips from slave # to master if 'role' in info : if info [ 'role' ] == "master" : data [ 'replication.master' ] = 1 data [ 'replication.master_sync_in_progress' ] = 0 else : data [ 'replication.master' ] = 0 # Connect to redis and get the maxmemory config value # Then calculate the % maxmemory of memory used maxmemory_config = self . _get_config ( host , port , unix_socket , auth , 'maxmemory' ) if maxmemory_config and 'maxmemory' in maxmemory_config . keys ( ) : maxmemory = float ( maxmemory_config [ 'maxmemory' ] ) # Only report % used if maxmemory is a non zero value if maxmemory == 0 : maxmemory_percent = 0.0 else : maxmemory_percent = info [ 'used_memory' ] / maxmemory * 100 maxmemory_percent = round ( maxmemory_percent , 2 ) data [ 'memory.used_percent' ] = float ( "%.2f" % maxmemory_percent ) # Iterate over the top level keys for key in self . _KEYS : if self . _KEYS [ key ] in info : data [ key ] = info [ self . _KEYS [ key ] ] # Iterate over renamed keys for 2.6 support for key in self . _RENAMED_KEYS : if self . _RENAMED_KEYS [ key ] in info : data [ key ] = info [ self . _RENAMED_KEYS [ key ] ] # Look for databaase speific stats for dbnum in range ( 0 , int ( self . config . get ( 'databases' , self . _DATABASE_COUNT ) ) ) : db = 'db%i' % dbnum if db in info : for key in info [ db ] : data [ '%s.%s' % ( db , key ) ] = info [ db ] [ key ] # Time since last save for key in [ 'last_save_time' , 'rdb_last_save_time' ] : if key in info : data [ 'last_save.time_since' ] = int ( time . time ( ) ) - info [ key ] # Publish the data to graphite for key in data : self . publish ( self . _publish_key ( nick , key ) , data [ key ] , precision = self . _precision ( data [ key ] ) , metric_type = 'GAUGE' )