from socket import error as SocketError from hiredis import ReplyError from retrying import retry from redistrib.clusternode import Talker, pack_command, ClusterNode from influxdb.client import InfluxDBClientError import sqlalchemy as db from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy.ext.declarative import declarative_base from algalon_cli import AlgalonClient import config import file_ipc import stats.db INTERVAL = 10 CMD_INFO = pack_command('info') CMD_CLUSTER_NODES = pack_command('cluster', 'nodes') CMD_PROXY = '+PROXY\r\n' COLUMNS = OrderedDict([ ('used_memory', 'used_memory'), ('used_memory_rss', 'used_memory_rss'), ('connected_clients', 'connected_clients'), ('total_commands_processed', 'total_commands_processed'), ('expired_keys', 'expired_keys'), ('evicted_keys', 'evicted_keys'), ('keyspace_hits', 'keyspace_hits'), ('keyspace_misses', 'keyspace_misses'), ('used_cpu_sys', 'used_cpu_sys'), ('used_cpu_user', 'used_cpu_user'), ('response_time', 'response_time'),
import time import logging from retrying import retry from redistrib.clusternode import Talker, pack_command, ClusterNode from socket import error as SocketError from hiredis import ReplyError import stats from eru_utils import eru_client from config import REDIS_CONNECT_TIMEOUT as CONNECT_TIMEOUT from models.base import db, Base CMD_INFO = pack_command('info') CMD_GET_MAXMEM = pack_command('config', 'get', 'maxmemory') CMD_CLUSTER_NODES = pack_command('cluster', 'nodes') CMD_PROXY = '+PROXY\r\n' def _info_slots(t): try: for line in t.talk_raw(CMD_CLUSTER_NODES).split('\n'): if len(line) == 0 or 'fail' in line or 'myself' not in line: continue node = ClusterNode(*line.split(' ')) return { 'node_id': node.node_id, 'slave': node.role_in_cluster != 'master', 'master_id': node.master_id if node.master_id != '-' else None, 'slots': node.assigned_slots, 'slots_migrating': node.slots_migrating, }
import time import logging from socket import error as SocketError from hiredis import ReplyError from retrying import retry from redistrib.clusternode import Talker, pack_command, ClusterNode from models.base import db, Base import stats.db CMD_INFO = pack_command('info') CMD_CLUSTER_NODES = pack_command('cluster', 'nodes') CMD_PROXY = '+PROXY\r\n' def _info_slots(t): try: for line in t.talk_raw(CMD_CLUSTER_NODES).split('\n'): if len(line) == 0 or 'fail' in line or 'myself' not in line: continue node = ClusterNode(*line.split(' ')) return { 'node_id': node.node_id, 'slave': node.role_in_cluster != 'master', 'master_id': node.master_id if node.master_id != '-' else None, 'slots': node.assigned_slots, 'slots_migrating': node.slots_migrating, } except (ValueError, LookupError, ReplyError): return {
import os import logging import redistrib.command as comm from socket import error as SocketError from hiredis import ReplyError from redistrib.clusternode import Talker, pack_command import node as nm CMD_PING = pack_command('ping') def recover(): logging.info('Run recovering on process %d', os.getpid()) for node in nm.list_all_nodes(): _recover_instance(node) logging.info('Recovering finished on process %d', os.getpid()) def recover_by_addr(host, port): t = Talker(host, port) try: m = t.talk_raw(CMD_PING) if m.lower() != 'pong': raise ValueError('Expect pong but recv: %s' % m) node = nm.pick_by(host, port) finally: if t is not None: t.close()