Пример #1
0
def _info_proxy(host, port):
    t = Talker(host, port)
    try:
        now = time.time()
        i = t.talk_raw(CMD_PROXY)
        elapse = time.time() - now
        lines = i.split('\n')
        st = {}
        for ln in lines:
            k, v = ln.split(':')
            st[k] = v
        conns = sum([int(c) for c in st['clients_count'].split(',')])
        mem_buffer_alloc = sum([int(m) for m in
                                st['mem_buffer_alloc'].split(',')])
        return {
            'stat': True,
            'response_time': elapse,
            'threads': st['threads'],
            'version': st['version'],
            'conn': {
                'connected_clients': conns,
                'completed_commands': int(st['completed_commands']),
                'total_process_elapse': float(st['total_process_elapse']),
            },
            'mem': {'mem_buffer_alloc': mem_buffer_alloc},
        }
    finally:
        t.close()
Пример #2
0
 def _collect_stats(self):
     t = Talker(self.details['host'], self.details['port'])
     try:
         now = time.time()
         i = t.talk_raw(CMD_PROXY)
         elapse = time.time() - now
         lines = i.split('\n')
         st = {}
         for ln in lines:
             k, v = ln.split(':')
             st[k] = v
         conns = sum([int(c) for c in st['clients_count'].split(',')])
         mem_buffer_alloc = sum([int(m) for m in
                                 st['mem_buffer_alloc'].split(',')])
         self.details.update({
             'stat': True,
             'response_time': elapse,
             'threads': st['threads'],
             'version': st['version'],
             'conn': {
                 'connected_clients': conns,
                 'completed_commands': int(st['completed_commands']),
                 'total_process_elapse': float(st['total_process_elapse']),
             },
             'mem': {'mem_buffer_alloc': mem_buffer_alloc},
         })
         self.set_available(elapse)
     finally:
         t.close()
Пример #3
0
def _info_proxy(host, port):
    t = Talker(host, port)
    try:
        now = time.time()
        i = t.talk_raw(CMD_PROXY)
        elapse = time.time() - now
        lines = i.split('\n')
        st = {}
        for ln in lines:
            k, v = ln.split(':')
            st[k] = v
        conns = sum([int(c) for c in st['clients_count'].split(',')])
        mem_buffer_alloc = sum(
            [int(m) for m in st['mem_buffer_alloc'].split(',')])
        return {
            'stat': True,
            'response_time': elapse,
            'threads': st['threads'],
            'version': st['version'],
            'conn': {
                'connected_clients': conns,
                'completed_commands': int(st['completed_commands']),
                'total_process_elapse': float(st['total_process_elapse']),
            },
            'mem': {
                'mem_buffer_alloc': mem_buffer_alloc
            },
        }
    finally:
        t.close()
Пример #4
0
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()
Пример #5
0
    def _collect_stats(self):
        t = Talker(self.details['host'], self.details['port'], CONNECT_TIMEOUT)
        try:
            now = time.time()
            i = t.talk_raw(CMD_PROXY)
            lines = i.split('\n')
            st = {}
            for ln in lines:
                k, v = ln.split(':', 1)
                st[k] = v
            conns = sum([int(c) for c in st['clients_count'].split(',')])
            mem_buffer_alloc = sum(
                [int(m) for m in st['mem_buffer_alloc'].split(',')])

            self.details.update({
                'stat':
                True,
                'threads':
                st['threads'],
                'version':
                st['version'],
                'used_cpu_sys':
                float(st.get('used_cpu_sys', 0)),
                'used_cpu_user':
                float(st.get('used_cpu_user', 0)),
                'conn': {
                    'connected_clients': conns,
                    'completed_commands': int(st['completed_commands']),
                    'total_process_elapse': float(st['total_process_elapse']),
                },
                'mem': {
                    'mem_buffer_alloc': mem_buffer_alloc
                },
                'read_slave':
                st.get('read_slave') == '1',
            })

            if 'last_command_elapse' in st:
                self.details['command_elapse'] = max(
                    [float(x) for x in st['last_command_elapse'].split(',')])
            else:
                self.details['command_elapse'] = 0

            if 'last_remote_cost' in st:
                self.details['remote_cost'] = max(
                    [float(x) for x in st['last_remote_cost'].split(',')])
            else:
                self.details['remote_cost'] = 0

            self.set_available(self.details['command_elapse'])
        finally:
            t.close()
Пример #6
0
    def _collect_stats(self, alarm_func):
        t = Talker(self.details['host'], self.details['port'], CONNECT_TIMEOUT)
        try:
            now = time.time()
            i = t.talk_raw(CMD_PROXY)
            lines = i.split('\n')
            st = {}
            for ln in lines:
                k, v = ln.split(':', 1)
                st[k] = v
            conns = sum([int(c) for c in st['clients_count'].split(',')])
            mem_buffer_alloc = sum([int(m) for m in
                                    st['mem_buffer_alloc'].split(',')])
            cluster_ok = st.get('cluster_ok') != '0'
            self.details.update({
                'stat': cluster_ok,
                'threads': st['threads'],
                'version': st['version'],
                'used_cpu_sys': float(st.get('used_cpu_sys', 0)),
                'used_cpu_user': float(st.get('used_cpu_user', 0)),
                'connected_clients': conns,
                'completed_commands': int(st['completed_commands']),
                'total_process_elapse': float(st['total_process_elapse']),
                'mem_buffer_alloc': mem_buffer_alloc,
                'read_slave': st.get('read_slave') == '1',
                'cluster_ok': cluster_ok,
            })

            if 'last_command_elapse' in st:
                self.details['command_elapse'] = max(
                    [float(x) for x in st['last_command_elapse'].split(',')])
            else:
                self.details['command_elapse'] = 0

            if 'last_remote_cost' in st:
                self.details['remote_cost'] = max(
                    [float(x) for x in
                     st['last_remote_cost'].split(',')])
            else:
                self.details['remote_cost'] = 0

            if cluster_ok:
                self.set_available(self.details['command_elapse'])
            else:
                self.send_alarm(alarm_func)
                self.set_unavailable()
        finally:
            t.close()