Chinaunix首页 | 论坛 | 博客
  • 博客访问: 57134
  • 博文数量: 11
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 164
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-15 09:42
文章分类

全部博文(11)

文章存档

2015年(1)

2014年(10)

我的朋友

分类: 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])
      

阅读(4716) | 评论(0) | 转发(0) |
1

上一篇:没有了

下一篇:saltstck配置权限控制普通用户执行命令

给主人留下些什么吧!~~