Python 监控Redis状态

install Redis Python driver:

wget https://github.com/downloads/andymccurdy/redis-py/redis-2.4.10.tar.gz

sudo python setup.py install

while true; do ./dump.py; sleep 10; done

dump.py

#!/usr/ali/bin/python
# -*- coding:utf8 -*-

import redis

def dump(ip, port, name):
  try:
    server = redis.Redis(ip, port, db=0)
    keynum = server.dbsize()
    memsize = server.info()['used_memory_human']
    print "%s %s:%d keyNum:%d memSize:%s" % (name, ip, port, keynum, memsize)
  except:
    print "%s %s:%d connect exception" % (name, ip, port)

if __name__ == "__main__":
  print "\nredis status ................."
  dump('10.249.211.91', 6379, 'front')
  dump('10.249.211.96', 6379, 'front')
  dump('10.249.211.16', 6379, 'front')
  dump('10.249.212.10', 6379, 'backup')
  dump('10.249.211.21', 6379, 'backup')
  dump('10.249.212.15', 6379, 'master')
  dump('10.249.211.46', 6379, 'slave')
  print "redis status .................\n"

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/psxff.html