(self, instance, base_url, object_type, vhosts, limit_vhosts, custom_tags)
Collect metrics on currently open connection per vhost.
Collect metrics on currently open connection per vhost.
Collect metrics on currently open connection per vhost .
def get_connections_stat(self, instance, base_url, object_type, vhosts, limit_vhosts, custom_tags):
        """
        Collect metrics on currently open connection per vhost.
        """
        grab_all_data = True

        if self._limit_vhosts(instance):
            grab_all_data = False
            data = []
            for vhost in vhosts:
                url = "vhosts/{}/{}".format(quote_plus(vhost), object_type)
                try:
                    data += self._get_data(urljoin(base_url, url))
                except Exception as e:
                    # This will happen if there is no connection data to grab
                    self.log.debug("Couldn't grab connection data from vhost, %s: %s", vhost, e)

        # sometimes it seems to need to fall back to this
        if grab_all_data or not len(data):
            data = self._get_data(urljoin(base_url, object_type))

        stats = {vhost: 0 for vhost in vhosts}
        connection_states = defaultdict(int)
        for conn in data:
            if conn['vhost'] in vhosts:
                stats[conn['vhost']] += 1
                # 'state' does not exist for direct type connections.
                connection_states[conn.get('state', 'direct')] += 1

        for vhost, nb_conn in iteritems(stats):
            self.gauge('rabbitmq.connections', nb_conn, tags=['{}_vhost:{}'.format(TAG_PREFIX, vhost)] + custom_tags)

        for conn_state, nb_conn in iteritems(connection_states):
            self.gauge(
                'rabbitmq.connections.state',
                nb_conn,
                tags=['{}_conn_state:{}'.format(TAG_PREFIX, conn_state)] + custom_tags,
            )
def get_connections_stat ( self , instance , base_url , object_type , vhosts , limit_vhosts , custom_tags ) : grab_all_data = True if self . _limit_vhosts ( instance ) : grab_all_data = False data = [ ] for vhost in vhosts : url = "vhosts/{}/{}" . format ( quote_plus ( vhost ) , object_type ) try : data += self . _get_data ( urljoin ( base_url , url ) ) except Exception as e : # This will happen if there is no connection data to grab self . log . debug ( "Couldn't grab connection data from vhost, %s: %s" , vhost , e ) # sometimes it seems to need to fall back to this if grab_all_data or not len ( data ) : data = self . _get_data ( urljoin ( base_url , object_type ) ) stats = { vhost : 0 for vhost in vhosts } connection_states = defaultdict ( int ) for conn in data : if conn [ 'vhost' ] in vhosts : stats [ conn [ 'vhost' ] ] += 1 # 'state' does not exist for direct type connections. connection_states [ conn . get ( 'state' , 'direct' ) ] += 1 for vhost , nb_conn in iteritems ( stats ) : self . gauge ( 'rabbitmq.connections' , nb_conn , tags = [ '{}_vhost:{}' . format ( TAG_PREFIX , vhost ) ] + custom_tags ) for conn_state , nb_conn in iteritems ( connection_states ) : self . gauge ( 'rabbitmq.connections.state' , nb_conn , tags = [ '{}_conn_state:{}' . format ( TAG_PREFIX , conn_state ) ] + custom_tags , )