diff --git a/src/redis-monitor.py b/src/redis-monitor.py index bd79b9f..bba0e95 100755 --- a/src/redis-monitor.py +++ b/src/redis-monitor.py @@ -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 @@ -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() \ No newline at end of file + 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) + + diff --git a/src/www/js/views/info-widget-view.js b/src/www/js/views/info-widget-view.js index 95b7724..32836cf 100644 --- a/src/www/js/views/info-widget-view.js +++ b/src/www/js/views/info-widget-view.js @@ -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()