Ejemplo n.º 1
0
    def run(self):

        statsProvider = RedisLiveDataProvider.GetProvider()
        pool = redis.ConnectionPool(host=self.server,
                                    port=self.port,
                                    db=0,
                                    password=self.password)
        monitor = Monitor(pool)
        commands = monitor.monitor()

        for command in commands:
            try:

                parts = command.split(" ")

                if len(parts) == 1:
                    continue

                t = parts[0].strip()
                epoch = float(t)
                timestamp = datetime.datetime.fromtimestamp(epoch)

                # Strip '(db N)' and '[N x.x.x.x:xx]' out of the monitor str
                if (parts[1] == "(db") or (parts[1][0] == "["):
                    parts = [parts[0]] + parts[3:]

                command = parts[1].replace('"', '').upper()

                if len(parts) > 2:
                    keyname = parts[2].replace('"', '').strip()
                else:
                    keyname = None

                if len(parts) > 3:
                    arguments = ""
                    for x in xrange(3, len(parts)):
                        arguments += " " + parts[x].replace('"', '')
                    arguments = arguments.strip()
                else:
                    arguments = None

                if command != 'INFO' and command != 'MONITOR':
                    statsProvider.SaveMonitorCommand(self.id, timestamp,
                                                     command, str(keyname),
                                                     str(arguments))

            except Exception, e:
                tb = traceback.format_exc()
                print "==============================\n"
                print datetime.datetime.now()
                print tb
                print command
                print "==============================\n"

            if self.stopped():
                break
Ejemplo n.º 2
0
    def run(self):

        statsProvider = RedisLiveDataProvider.GetProvider()
        redisClient = redis.StrictRedis(host=self.server,
                                        port=self.port,
                                        db=0,
                                        password=self.password)

        while not self.stopped():
            try:
                redisInfo = redisClient.info()
                currentTime = datetime.datetime.now()
                used_memory = int(redisInfo['used_memory'])

                # used_memory_peak not available in older versions of redis
                try:
                    peak_memory = int(redisInfo['used_memory_peak'])
                except:
                    peak_memory = used_memory

                statsProvider.SaveMemoryInfo(self.id, currentTime, used_memory,
                                             peak_memory)
                statsProvider.SaveInfoCommand(self.id, currentTime, redisInfo)

                # databases=[]
                # for key in sorted(redisInfo.keys()):
                # 	if key.startswith("db"):
                # 		database = redisInfo[key]
                # 		database['name']=key
                # 		databases.append(database)

                # expires=0
                # persists=0
                # for database in databases:
                # 	expires+=database.get("expires")
                # 	persists+=database.get("keys")-database.get("expires")

                # statsProvider.SaveKeysInfo(self.id, currentTime, expires, persists)

                time.sleep(1)

            except Exception, e:
                tb = traceback.format_exc()
                print "==============================\n"
                print datetime.datetime.now()
                print tb
                print "==============================\n"
Ejemplo n.º 3
0
class BaseController(tornado.web.RequestHandler):

    statsProvider = RedisLiveDataProvider.GetProvider()

    def DateTimeToList(self, datetime):
        parsedDate = dateutil.parser.parse(datetime)
        return [
            parsedDate.year, parsedDate.month, parsedDate.day, parsedDate.hour,
            parsedDate.minute, parsedDate.second
        ]

    # todo : fix this
    def AverageData(self, data):
        average = []

        deviation = 1024 * 1024

        start = dateutil.parser.parse(data[0][0])
        end = dateutil.parser.parse(data[-1][0])
        difference = end - start
        weeks, days = divmod(difference.days, 7)
        minutes, seconds = divmod(difference.seconds, 60)
        hours, minutes = divmod(minutes, 60)

        if difference.days > 0:
            current_max = 0
            current_current = 0
            current_d = 0
            for dt, maxMemory, currentMemory in data:
                d = dateutil.parser.parse(dt)
                if d.day != current_d:
                    current_d = d.day
                    average.append([dt, maxMemory, currentMemory])
                    current_max = maxMemory
                    current_current = currentMemory
                else:
                    if maxMemory > current_max or currentMemory > current_current:
                        average.pop()
                        average.append([dt, maxMemory, currentMemory])
                        current_max = maxMemory
                        current_current = currentMemory
        elif hours > 0:
            current_max = 0
            current_current = 0
            current = -1
            keep_flag = False
            for dt, maxMemory, currentMemory in data:
                d = dateutil.parser.parse(dt)
                if d.hour != current:
                    current = d.hour
                    average.append([dt, maxMemory, currentMemory])
                    current_max = maxMemory
                    current_current = currentMemory
                    keep_flag = False
                elif abs(maxMemory - current_max) > deviation or abs(
                        currentMemory - current_current) > deviation:
                    #average.pop()
                    average.append([dt, maxMemory, currentMemory])
                    current_max = maxMemory
                    current_current = currentMemory
                    keep_flag = True
                elif maxMemory > current_max or currentMemory > current_current:
                    if keep_flag != True:
                        average.pop()
                    average.append([dt, maxMemory, currentMemory])
                    current_max = maxMemory
                    current_current = currentMemory
                    keep_flag = False
        else:
            current_max = 0
            current_current = 0
            current_m = -1
            keep_flag = False
            for dt, maxMemory, currentMemory in data:
                d = dateutil.parser.parse(dt)
                if d.minute != current_m:
                    current_m = d.minute
                    average.append([dt, maxMemory, currentMemory])
                    current_max = maxMemory
                    current_current = currentMemory
                    keep_flag = False
                elif abs(maxMemory - current_max) > deviation or abs(
                        currentMemory - current_current) > deviation:
                    #average.pop()
                    average.append([dt, maxMemory, currentMemory])
                    current_max = maxMemory
                    current_current = currentMemory
                    keep_flag = True
                elif maxMemory > current_max or currentMemory > current_current:
                    if keep_flag != True:
                        average.pop()
                    average.append([dt, maxMemory, currentMemory])
                    current_max = maxMemory
                    current_current = currentMemory
                    keep_flag = False

        return average