Skip to content

Commit

Permalink
added support to run monitoring only for specified duration
Browse files Browse the repository at this point in the history
  • Loading branch information
kumarnitin committed Jun 17, 2012
1 parent be2584b commit f0b724b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 32 deletions.
85 changes: 54 additions & 31 deletions src/redis-monitor.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
#! /usr/bin/env python

import socket

import datetime
import threading
import time
from time import strftime

import threading
from threading import Timer

import redis
import traceback
import datetime
import argparse


#from dataprovider.sqliteprovider import RedisStatsProvider
from dataprovider.redisprovider import RedisStatsProvider


class Monitor():
class Monitor(object):

def __init__(self, connection_pool):
self.connection_pool = connection_pool
self.connection = None
Expand Down Expand Up @@ -159,42 +164,60 @@ def run(self):
print tb
print "==============================\n"

def main():
class RedisMonitor(object):

def __init__(self):
self.threads = []
self.active = True

def Run(self, duration):

redisServers = ReadServerConfig()
redisServers = self.ReadServerConfig()

threads = []
for redisServer in redisServers:
monitor = MonitorThread(redisServer["server"], redisServer["port"])
self.threads.append(monitor)
monitor.setDaemon(True)
monitor.start()

for redisServer in redisServers:
monitor = MonitorThread(redisServer["server"], redisServer["port"])
threads.append(monitor)
monitor.setDaemon(True)
monitor.start()
info = InfoThread(redisServer["server"], redisServer["port"])
self.threads.append(info)
info.setDaemon(True)
info.start()

info = InfoThread(redisServer["server"], redisServer["port"])
threads.append(info)
info.setDaemon(True)
info.start()
t = Timer(duration, self.Stop)
t.start()

try:
while self.active:
pass
except (KeyboardInterrupt, SystemExit):
self.Stop()

def Stop(self):
print "shutting down..."
for t in self.threads:
t.stop()
self.active = False

try:
while True:
pass
except (KeyboardInterrupt, SystemExit):
for t in threads:
t.stop()
def ReadServerConfig(self):
redisServers = []
f = open("config.ini")
for line in f:
if line[0]=="#":
continue
parts=line.rstrip('\r\n').split(':')
redisServers.append({ "server" : parts[0], "port" : int(parts[1])})

def ReadServerConfig():
redisServers = []
f = open("config.ini")
for line in f:
if line[0]=="#":
continue
parts=line.rstrip('\r\n').split(':')
redisServers.append({ "server" : parts[0], "port" : int(parts[1])})
return redisServers

return redisServers

if __name__ == '__main__':
main()
parser = argparse.ArgumentParser(description='Monitor redis.')
parser.add_argument('--duration', type = int, help = "duration to run the monitor command (in seconds)", required = True)
args = parser.parse_args()
duration = args.duration
monitor = RedisMonitor()
monitor.Run(duration)


2 changes: 1 addition & 1 deletion src/www/js/views/info-widget-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var InfoWidget = BaseWidget.extend({
this.Name = "Info Widget"

this.init()
this.updateFrequency = 10000 // every 10 seconds
this.updateFrequency = 5000 // every 5 seconds

// templates
var templateSource = $("#info-widget-template").html()
Expand Down

0 comments on commit f0b724b

Please sign in to comment.