123456789101112131415161718192021222324252627282930313233343536373839 |
- # coding: utf-8
- import redis
- import sys
- redis_master_list = ['192.168.4.11:6379',]
- def getredisinfo(ip, port):
- try:
- r = redis.StrictRedis(host=ip, port=port, db=0)
- # print 'redis ip:', ip
- # print 'role:', r.info()['role']
- # print 'used_memory_human:', r.info()['used_memory_human']
- # print 'connected_clients:', r.info()['connected_clients']
- # print 'blocked_clients:', r.info()['blocked_clients']
- # print 'connected_slaves:', r.info()['connected_slaves']
- # print '--' * 60
- # for k,v in r.info().items():
- # print k,v
- # sys.exit()
- if r.info().get('slave0'):
- n = 0
- while 1:
- slave_num = 'slave' + str(n)
- if not r.info().get(slave_num):
- break
- print slave_num, r.info()[slave_num]
- ip = r.info()[slave_num]['ip']
- port = r.info()[slave_num]['port']
- getredisinfo(ip, port)
- n += 1
- except redis.exceptions.ConnectionError:
- print 'Unable to connect %s:%s' % (ip, port)
- for host in redis_master_list:
- print '==' * 60
- ip,port = host.split(':')
- getredisinfo(ip, int(port))
|