Пример #1
0
    def get(self, key, all=False, host=None, port=None):
        """Command: cli config get [key]

        :param key: redis config keyword
        :param all: If True, command to all nodes
        :param host: host
        :param port: port
        """
        sub_cmd = 'config get "{key}"'.format(key=key)
        if all:
            RedisCliUtil.command_all(sub_cmd=sub_cmd, formatter=print_table)
        else:
            RedisCliUtil.command(sub_cmd=sub_cmd, host=host, port=port)
Пример #2
0
 def rowcount(self):
     """Query and show cluster row count"""
     logger.debug('rowcount')
     # open-redis-cli-all info Tablespace | grep totalRows | awk -F ',
     # ' '{print $4}' | awk -F '=' '{sum += $2} END {print sum}'
     ip_list = config.get_node_ip_list()
     port_list = config.get_master_port_list()
     outs, meta = RedisCliUtil.command_raw_all('info Tablespace', ip_list,
                                               port_list)
     lines = outs.splitlines()
     key = 'totalRows'
     filtered_lines = (filter(lambda x: key in x, lines))
     ld = RedisCliUtil.to_list_of_dict(filtered_lines)
     # row_count = reduce(lambda x, y: {key: int(x[key]) + int(y[key])}, ld)
     row_count = reduce(lambda x, y: x + int(y[key]), ld, 0)
     self._print(row_count)
Пример #3
0
    def slots(self):
        """Command: cli cluster slots"""
        def formatter(outs):
            lines = outs.splitlines()
            replicas = config.get_replicas()
            column_count = 2 + 2 * (replicas + 1)
            row_count = len(lines) / column_count
            header = [['start', 'end', 'm_ip', 'm_port']]
            remain = column_count - 4
            data = []
            for i in range(0, remain / 2):
                header[0].append('s_ip_%d' % i)
                header[0].append('s_port_%d' % i)
            for i in range(0, row_count):
                data.append(lines[i * column_count:column_count * (i + 1)])
            data.sort(key=lambda x: int(x[0]))
            table = AsciiTable(header + data)
            print(table.table)

        RedisCliUtil.command('cluster slots', formatter=formatter)
Пример #4
0
Файл: sql.py Проект: mnms/share
 def __set_maxmemory(self, cluster_id_of_table, cols):
     key = 'maxmemory'
     try:
         sub_cmd = 'config get "{key}"'.format(key=key)
         raw = RedisCliUtil.command(sub_cmd=sub_cmd,
                                    mute=True,
                                    cluster_id=cluster_id_of_table)
         v = int(raw.splitlines()[1])
         cols[key] = '{:,} bytes'.format(v)
     except:
         cols[key] = 'error'
Пример #5
0
Файл: sql.py Проект: mnms/share
    def __set_ttl(self, cluster_id_of_table, cols):
        def _filter(raw):
            seconds = int(raw)
            return '%s (%s)' % (raw, str(datetime.timedelta(seconds=seconds)))

        key = 'flash-db-ttl'
        try:
            sub_cmd = 'config get "{key}"'.format(key=key)
            v = RedisCliUtil.command(sub_cmd=sub_cmd,
                                     mute=True,
                                     cluster_id=cluster_id_of_table)
            cols[key] = _filter(v.splitlines()[1])
        except:
            cols[key] = 'error'
Пример #6
0
Файл: sql.py Проект: mnms/share
 def __set_tablespace(self, cluster_id_of_table, cols):
     tablespace_lines = RedisCliUtil.command(sub_cmd='info tablespace',
                                             mute=True,
                                             cluster_id=cluster_id_of_table)
     keywords = ['numPartitionColumns', 'partitionColumns', 'partitions']
     lines = tablespace_lines.splitlines()
     for line in lines:
         for keyword in keywords:
             if keyword in line:
                 left = line.split(keyword + '=')[1]
                 if ',' in left:
                     value = left.split(',')[0]
                     cols[keyword] = value
                 else:
                     cols[keyword] = left
Пример #7
0
    def _get_ip_port_dict_using_cluster_nodes_cmd():
        def mute_formatter(outs):
            pass

        outs = RedisCliUtil.command(sub_cmd='cluster nodes',
                                    formatter=mute_formatter)
        lines = outs.splitlines()
        d = {}
        for line in lines:
            rows = line.split(' ')
            addr = rows[1]
            if 'connected' in rows:
                (host, port) = addr.split(':')
                if host not in d:
                    d[host] = [port]
                else:
                    d[host].append(port)
        return d
Пример #8
0
    def set(self, key, value, save, all=False, host=None, port=None):
        """Command: cli config set [key] [value]

        :param key: redis config keyword
        :param value: value
        :param save: If True, save value to config file
        :param all: If True, command to all nodes
        :param host: host
        :param port: port
        """
        tr = TableReport(['step', 'result'])
        sub_cmd = 'config set {key} {value}'.format(key=key, value=value)
        if all:
            RedisCliUtil.command_all(sub_cmd=sub_cmd, formatter=print_table)
        else:
            RedisCliUtil.command(sub_cmd=sub_cmd, host=host, port=port)
        if save:
            RedisCliUtil.save_redis_template_config(key, value)
            cluster_util.rsync_fb_conf()
            Center().update_redis_conf()
Пример #9
0
 def nodes(self):
     """Command: cli cluster nodes"""
     RedisCliUtil.command('cluster nodes')
Пример #10
0
 def info(self):
     """Command: cli cluster info"""
     RedisCliUtil.command('cluster info')
Пример #11
0
 def replication(self, host=None, port=None):
     """Command: cli info replication"""
     RedisCliUtil.command('info replication', host=host, port=port)
Пример #12
0
 def tablespace(self, host=None, port=None):
     """Command: cli info tablespace"""
     RedisCliUtil.command(sub_cmd='info tablespace', host=host, port=port)
Пример #13
0
 def eviction(self, host=None, port=None):
     """Command: cli info eviction"""
     RedisCliUtil.command(sub_cmd='info eviction', host=host, port=port)
Пример #14
0
 def memory(self, host=None, port=None):
     """Command: cli info memory"""
     RedisCliUtil.command(sub_cmd='info memory', host=host, port=port)
Пример #15
0
 def all(self, host=None, port=None):
     """Command: cli info all"""
     RedisCliUtil.command(sub_cmd='info', host=host, port=port)