分类: Python/Ruby
2014-02-12 17:14:01
#!/usr/local/bin/python
from __future__ import division
import redis,time
import sys,os
import socket
def getInfo(ip,port,num):
data=""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(2)
s.connect((ip,port))
r = redis.Redis(host=ip,port=port,db=num)
#print dir(r)
info = r.info()
used_memory = str(info["used_memory"])
role = str(info["role"])
appendonly = str(r.config_get("appendonly")[1])
maxmemory = str(r.config_get("maxmemory")[1])
ping = str(r.ping())
data+=used_memory+","+role+","+appendonly+","+maxmemory+","+ping
return data
except Exception:
return "-1,-1,-1,-1,-1"
def monitor_used_memory(file):
for info in open(file):
system = str(info.split(",")[0])
ip = str(info.split(",")[1])
port = int(info.split(",")[2])
db_num = int(info.split(",")[3].strip("\n"))
used_memory = getInfo(ip,port,db_num).split(",")[0]
maxmemory = getInfo(ip,port,db_num).split(",")[3]
def monitor_aof(file):
for info in open(file):
system = str(info.split(",")[0])
ip = str(info.split(",")[1])
port = int(info.split(",")[2])
db_num = int(info.split(",")[3])
role = info.split(",")[4].strip("\n")
role_now = getInfo(ip,port,db_num).split(",")[1]
aof = getInfo(ip,port,db_num).split(",")[2]
def monitor_ping(file):
for info in open(file):
system = str(info.split(",")[0])
ip = str(info.split(",")[1])
port = int(info.split(",")[2])
db_num = int(info.split(",")[3].strip("\n"))
ping = str(getInfo(ip,port,db_num).split(",")[4])