示例#1
0
    def __init__(self, master):
        self.rbldnsd = master
        self.startup = time.time()
        template = """running: ${runningsince} - ${qps} q/s
$zonedatasetlist        
"""
        
        variables = {
              'runningsince':self._tmpl_runninsince,
              #'zonelist':self._tmpl_zonelist,
              #'datasetlist':self._tmpl_datasetlist,
              'zonedatasetlist':self._tmpl_zonedatasetlist,
              'qps':self._tmpl_qps,
        }
        
        self.netconsole = RuleyConsole(template, variables)
        
        self.querybuffer = {}
        self.buffertime = 5 
        self.serversocket=None
示例#2
0
    def __init__(self, master):
        self.rbldnsd = master
        self.startup = time.time()
        template = """running: ${runningsince} - ${qps} q/s
$zonedatasetlist        
"""

        variables = {
            "runningsince": self._tmpl_runninsince,
            #'zonelist':self._tmpl_zonelist,
            #'datasetlist':self._tmpl_datasetlist,
            "zonedatasetlist": self._tmpl_zonedatasetlist,
            "qps": self._tmpl_qps,
        }

        self.netconsole = RuleyConsole(template, variables)

        self.querybuffer = {}
        self.buffertime = 5
        self.serversocket = None
示例#3
0
class StatusMonitor(object):
    def __init__(self, master):
        self.rbldnsd = master
        self.startup = time.time()
        template = """running: ${runningsince} - ${qps} q/s
$zonedatasetlist        
"""

        variables = {
            "runningsince": self._tmpl_runninsince,
            #'zonelist':self._tmpl_zonelist,
            #'datasetlist':self._tmpl_datasetlist,
            "zonedatasetlist": self._tmpl_zonedatasetlist,
            "qps": self._tmpl_qps,
        }

        self.netconsole = RuleyConsole(template, variables)

        self.querybuffer = {}
        self.buffertime = 5
        self.serversocket = None

    def _tmpl_runninsince(self):
        return make_escaped_string(secs2human(int(time.time() - self.startup)), fg=ConsoleConstants.COLOR_CYAN)

    def _tmpl_qps(self):
        slottime = 5
        now = time.time()
        then = now - slottime
        bufferkeys = self.querybuffer.keys()
        counter = 0
        for k in bufferkeys:
            if k > then:
                counter += 1
        qps = float(counter) / float(slottime)
        return make_escaped_string("%.2f" % qps, fg=ConsoleConstants.COLOR_BLUE, bg=ConsoleConstants.COLOR_WHITE)

    def add_query(self, query):
        self.querybuffer[time.time()] = query

    def _tmpl_zonelist(self):
        tmpl = ""
        for zonename, zone in self.rbldnsd.zones.iteritems():
            if not zone.is_available():
                display = make_escaped_string(zonename, ConsoleConstants.COLOR_RED)
            elif zone.is_reloading():
                display = make_escaped_string(zonename, ConsoleConstants.COLOR_YELLOW)
            else:
                display = make_escaped_string(zonename, ConsoleConstants.COLOR_GREEN)
            tmpl += " " + display
        return tmpl

    def _tmpl_datasetlist(self):
        tmpl = ""

        for filename, dataset in self.rbldnsd.datasets.iteritems():
            if not dataset.available:
                activetime = "unavailable"
                filename = make_escaped_string(filename, ConsoleConstants.COLOR_RED)
            elif dataset.reloading:
                filename = make_escaped_string(filename, ConsoleConstants.COLOR_YELLOW)
                activetime = "(reloading)"
            else:
                filename = make_escaped_string(filename, ConsoleConstants.COLOR_GREEN)
                humanreadableactivetime = secs2human(int(time.time() - dataset.activesince))
                activetime = make_escaped_string(humanreadableactivetime, ConsoleConstants.COLOR_CYAN)

            reloadinfo = dataset.lastreloadinfo
            if reloadinfo == None:
                info = ""
            else:
                (loadtime, newcount, diff) = reloadinfo
                loadtime = "%.2fs" % loadtime
                if diff >= 0:
                    diff = "+%s" % diff
                newcount = make_escaped_string(newcount, ConsoleConstants.COLOR_MAGENTA)
                info = "loadtime: %s , %s records(%s)" % (loadtime, newcount, diff)

            tmpl += "%s age: %s %s\n" % (filename, activetime, info)
        return tmpl

    def _tmpl_zonedatasetlist(self):
        """zone+dataset combined"""
        tmpl = ""
        for zonename, zone in self.rbldnsd.zones.iteritems():
            if not zone.is_available():
                display = make_escaped_string(zonename, ConsoleConstants.COLOR_RED)
            elif zone.is_reloading():
                display = make_escaped_string(zonename, ConsoleConstants.COLOR_YELLOW)
            else:
                display = make_escaped_string(zonename, ConsoleConstants.COLOR_GREEN)
            tmpl += "\n" + display + ": \n"

            for dataset in zone.datasets:
                filename = dataset.filename

                if not dataset.available:
                    activetime = "unavailable"
                    filename = make_escaped_string(filename, ConsoleConstants.COLOR_RED)
                elif dataset.reloading:
                    filename = make_escaped_string(filename, ConsoleConstants.COLOR_YELLOW)
                    activetime = "(reloading)"
                else:
                    filename = make_escaped_string(filename, ConsoleConstants.COLOR_GREEN)
                    humanreadableactivetime = secs2human(int(time.time() - dataset.activesince))
                    activetime = make_escaped_string(humanreadableactivetime, ConsoleConstants.COLOR_CYAN)

                reloadinfo = dataset.lastreloadinfo
                if reloadinfo == None:
                    info = ""
                else:
                    (loadtime, newcount, diff) = reloadinfo
                    loadtime = "%.2fs" % loadtime
                    if diff >= 0:
                        diff = "+%s" % diff
                    newcount = make_escaped_string(newcount, ConsoleConstants.COLOR_MAGENTA)
                    info = "loadtime: %s , %s records(%s)" % (loadtime, newcount, diff)

                tmpl += " %s age: %s %s\n" % (filename, activetime, info)

        return tmpl

    def start(self):
        port = 5353
        logging.info("""**** monitor running on port %s *****""" % port)
        try:
            self.serversocket = self.netconsole.run_remote_console(port)
        except:
            logging.getLogger().error("Exception in run_remote_console: %s" % traceback.format_exc())

    def debug_console(self):
        self.netconsole.loop()

    def shutdown(self):
        self.netconsole.stop_looping()
        if self.serversocket != None:
            try:
                self.serversocket.close()
            except:
                pass
示例#4
0
class StatusMonitor(object):
    def __init__(self, master):
        self.rbldnsd = master
        self.startup = time.time()
        template = """running: ${runningsince} - ${qps} q/s
$zonedatasetlist        
"""
        
        variables = {
              'runningsince':self._tmpl_runninsince,
              #'zonelist':self._tmpl_zonelist,
              #'datasetlist':self._tmpl_datasetlist,
              'zonedatasetlist':self._tmpl_zonedatasetlist,
              'qps':self._tmpl_qps,
        }
        
        self.netconsole = RuleyConsole(template, variables)
        
        self.querybuffer = {}
        self.buffertime = 5 
        self.serversocket=None
    
    def _tmpl_runninsince(self):
        return make_escaped_string(secs2human(int(time.time() - self.startup)), fg=ConsoleConstants.COLOR_CYAN)
        
    def _tmpl_qps(self):
        slottime = 5
        now = time.time()
        then = now - slottime
        bufferkeys = self.querybuffer.keys()
        counter = 0
        for k in bufferkeys:
            if k > then:
                counter += 1
        qps = float(counter) / float(slottime)
        return make_escaped_string("%.2f" % qps, fg=ConsoleConstants.COLOR_BLUE, bg=ConsoleConstants.COLOR_WHITE)
    
    def add_query(self, query):
        self.querybuffer[time.time()] = query
    
    def _tmpl_zonelist(self):
        tmpl = ""
        for zonename, zone in self.rbldnsd.zones.iteritems():
            if not zone.is_available():
                display = make_escaped_string(zonename, ConsoleConstants.COLOR_RED)
            elif zone.is_reloading():
                display = make_escaped_string(zonename, ConsoleConstants.COLOR_YELLOW)
            else:
                display = make_escaped_string(zonename, ConsoleConstants.COLOR_GREEN)
            tmpl += " " + display
        return tmpl
    
    def _tmpl_datasetlist(self):
        tmpl = ""

        for filename, dataset in self.rbldnsd.datasets.iteritems():
            if not dataset.available:
                activetime = "unavailable"
                filename = make_escaped_string(filename, ConsoleConstants.COLOR_RED)
            elif dataset.reloading:
                filename = make_escaped_string(filename, ConsoleConstants.COLOR_YELLOW)
                activetime = "(reloading)"
            else:
                filename = make_escaped_string(filename, ConsoleConstants.COLOR_GREEN)
                humanreadableactivetime = secs2human(int(time.time() - dataset.activesince))
                activetime = make_escaped_string(humanreadableactivetime, ConsoleConstants.COLOR_CYAN)
            
            reloadinfo = dataset.lastreloadinfo
            if reloadinfo == None:
                info = ''
            else:
                (loadtime, newcount, diff) = reloadinfo
                loadtime = "%.2fs" % loadtime
                if diff >= 0:
                    diff = "+%s" % diff
                newcount = make_escaped_string(newcount, ConsoleConstants.COLOR_MAGENTA)
                info = "loadtime: %s , %s records(%s)" % (loadtime, newcount, diff)
                
                         
            tmpl += "%s age: %s %s\n" % (filename, activetime, info)
        return tmpl
    
    
    def _tmpl_zonedatasetlist(self):
        """zone+dataset combined"""
        tmpl = ""
        for zonename, zone in self.rbldnsd.zones.iteritems():
            if not zone.is_available():
                display = make_escaped_string(zonename, ConsoleConstants.COLOR_RED)
            elif zone.is_reloading():
                display = make_escaped_string(zonename, ConsoleConstants.COLOR_YELLOW)
            else:
                display = make_escaped_string(zonename, ConsoleConstants.COLOR_GREEN)
            tmpl += "\n"+display+": \n"
            
            
            for dataset in zone.datasets:
                filename=dataset.filename
                
                if not dataset.available:
                    activetime = "unavailable"
                    filename = make_escaped_string(filename, ConsoleConstants.COLOR_RED)
                elif dataset.reloading:
                    filename = make_escaped_string(filename, ConsoleConstants.COLOR_YELLOW)
                    activetime = "(reloading)"
                else:
                    filename = make_escaped_string(filename, ConsoleConstants.COLOR_GREEN)
                    humanreadableactivetime = secs2human(int(time.time() - dataset.activesince))
                    activetime = make_escaped_string(humanreadableactivetime, ConsoleConstants.COLOR_CYAN)
                
                reloadinfo = dataset.lastreloadinfo
                if reloadinfo == None:
                    info = ''
                else:
                    (loadtime, newcount, diff) = reloadinfo
                    loadtime = "%.2fs" % loadtime
                    if diff >= 0:
                        diff = "+%s" % diff
                    newcount = make_escaped_string(newcount, ConsoleConstants.COLOR_MAGENTA)
                    info = "loadtime: %s , %s records(%s)" % (loadtime, newcount, diff)
                    
                             
                tmpl += " %s age: %s %s\n" % (filename, activetime, info)
            
            
        return tmpl 
    
    def start(self):
        port = 5353
        logging.info("""**** monitor running on port %s *****""" % port)
        try:
            self.serversocket=self.netconsole.run_remote_console(port)
        except:
            logging.getLogger().error("Exception in run_remote_console: %s"%traceback.format_exc())
        

    def debug_console(self):
        self.netconsole.loop()
        
    def shutdown(self):
        self.netconsole.stop_looping()
        if self.serversocket!=None:
            try:
                self.serversocket.close()
            except:
                pass