示例#1
0
def stopMonitorThreads(config):
    monitors = cfg.getMonitors(config)
    for key in monitors:
        monitorConfig = cfg.loadMonitorConfig(config, key)
        monitorThread = thutil.getThread(cfg.THREAD_MONITOR +
                                         monitorConfig.key)
        if monitorThread: monitorThread.stopRun()
示例#2
0
def getMonitors(config):
    """
    Get Readers and Component Data
    """
    logger.info('getMonitors')
    monitorList = []
    for key in cfg.getMonitors(config):
        monitorConfig = cfg.loadMonitorConfig(config, key)
        r = {
            'monitorKey': monitorConfig.key,
            'components': monitorConfig.components,
            'host': monitorConfig.hostname,
            'type': monitorConfig.type,
            'enable': monitorConfig.enable,
            'interval': monitorConfig.interval
        }
        monitorList.append(r)

    data = {'monitors': monitorList}
    return data
示例#3
0
def startMonitorsThreads(config):
    """ 
    ===========================================================================
    Summary 
    ===========================================================================   
    
    **Args**:
        arg1
    **Returns**:
        None
    """     
    monitors = cfg.getMonitors(config)
    for key in monitors:
        monitorConfig = cfg.loadMonitorConfig(config, key)

        monitorThread = thutil.getThread(cfg.THREAD_MONITOR+monitorConfig.key)
        
        if monitorThread:
            logger.debug("Thread already running:"+monitorConfig.key)
            continue        
        
        if monitorConfig.enable:
            if monitorConfig.type == cfg.MONITOR_TYPE_HOST:
                monitorThread = monhost.MonitorHostThread(monitorConfig, th.OperationMode.NORMAL)
                monitorThread.start() 
            elif monitorConfig.type == cfg.MONITOR_TYPE_SPRINGMICROSERVICE:
                monitorThread = monmicroserv.MonitorMicroserviceThread(monitorConfig, th.OperationMode.NORMAL)
                monitorThread.start() 
            elif monitorConfig.type == cfg.MONITOR_TYPE_TOMCAT:
                monitorThread = montomcat.MonitorTomcatThread(monitorConfig, th.OperationMode.NORMAL)
                monitorThread.start()
            elif monitorConfig.type == cfg.MONITOR_TYPE_POSTGRES:
                monitorThread = monpsql.MonitorPostgresThread(monitorConfig, th.OperationMode.NORMAL)
                monitorThread.start()                
            else:
                logger.error("Invalid monitor type :"+str(monitorConfig.type))
示例#4
0
def setMonitorThreads(config, cmd, value):
    monitors = cfg.getMonitors(config)
    for key in monitors:
        monitorConfig = cfg.loadMonitorConfig(config, key)
        monitorThread = thutil.getThread(cfg.THREAD_MONITOR+monitorConfig.key)
        applyOptionInThread(monitorThread, cmd, value)
示例#5
0
            
        self.setState(th.ThreadState.ENDING)          
    

#%%
"""
*******************************************************************************
Module Execution
This code helps to developer to know the usage of the module
*******************************************************************************
"""
if __name__ == '__main__':    
    print('Start module execution:')
    logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%H:%M:%S')
    
    cfg.createDefaultConfigfile()
    config=cfg.loadConfig()  
    key='host'
    monitorConfig = cfg.loadMonitorConfig(config, key)
    t = MonitorHostThread( monitorConfig, th.OperationMode.NORMAL)   
    t.start()
    
    input("Press a key to finish")
    t.stopRun()
    
    #wait thread end
    t.join()
    
    print("loopCount="+str(t.loopCount)+",loopCount="+str(t.recordsProcessed),",bytesProcessed="+str(t.bytesProcessed))
    
    print("End module execution")
示例#6
0
    def execute(self, config=None):
        """
        ***********************************************************************
        
        ***********************************************************************
        """
        if not self.arg1:
            return cli.LogMapperCommandResponse(False, "Invalid option")

        if self.arg1 == 'agent':
            return cli.LogMapperCommandResponse(True,
                                                json.dumps(getAgent(config)))

        if self.arg1 == 'readers':
            return cli.LogMapperCommandResponse(True,
                                                json.dumps(getReaders(config)))

        if self.arg1 == 'monitors':
            return cli.LogMapperCommandResponse(
                True, json.dumps(getMonitors(config)))

        if self.arg1 == 'logkeys' and len(self.args) == 2:
            key = self.args[1]
            readerConfig = cfg.loadReaderConfig(config, key)
            return cli.LogMapperCommandResponse(
                True, json.dumps(getLogNodesByCategoryTrace(readerConfig)))

        if self.arg1 == 'paths' and len(self.args) == 2:
            key = self.args[1]
            readerConfig = cfg.loadReaderConfig(config, key)
            return cli.LogMapperCommandResponse(
                True, json.dumps(getLogPaths(readerConfig)))

        if self.arg1 == 'pathMeasures' and len(self.args) == 4:
            key = self.args[1]
            readerConfig = cfg.loadReaderConfig(config, key)
            start = datetime.datetime.strptime(self.args[2], '%Y-%m-%dT%H:%M')
            end = datetime.datetime.strptime(self.args[3], '%Y-%m-%dT%H:%M')
            return cli.LogMapperCommandResponse(
                True, json.dumps(getJsonPathMeasures(readerConfig, start,
                                                     end)))

        if self.arg1 == 'logEventsCount' and len(self.args) == 4:
            key = self.args[1]
            readerConfig = cfg.loadReaderConfig(config, key)
            start = datetime.datetime.strptime(self.args[2], '%Y-%m-%dT%H:%M')
            end = datetime.datetime.strptime(self.args[3], '%Y-%m-%dT%H:%M')
            return cli.LogMapperCommandResponse(
                True,
                json.dumps(getJsonLogEventsCount(readerConfig, start, end)))

        if self.arg1 == 'logMetrics' and len(self.args) == 4:
            key = self.args[1]
            readerConfig = cfg.loadReaderConfig(config, key)
            start = datetime.datetime.strptime(self.args[2], '%Y-%m-%dT%H:%M')
            end = datetime.datetime.strptime(self.args[3], '%Y-%m-%dT%H:%M')
            return cli.LogMapperCommandResponse(
                True, json.dumps(getJsonLogMetrics(readerConfig, start, end)))

        if self.arg1 == 'logMetricsColnames' and len(self.args) == 2:
            key = self.args[1]
            readerConfig = cfg.loadReaderConfig(config, key)
            return cli.LogMapperCommandResponse(
                True, json.dumps(getJsonLogColnames(readerConfig)))

        if self.arg1 == 'monMeasures' and len(self.args) == 4:
            key = self.args[1]
            monitorConfig = cfg.loadMonitorConfig(config, key)
            start = datetime.datetime.strptime(self.args[2], '%Y-%m-%dT%H:%M')
            end = datetime.datetime.strptime(self.args[3], '%Y-%m-%dT%H:%M')
            return cli.LogMapperCommandResponse(
                True,
                json.dumps(getJsonMonitorMeasures(monitorConfig, start, end)))

        if self.arg1 == 'monMeasuresColnames' and len(self.args) == 2:
            key = self.args[1]
            monitorConfig = cfg.loadMonitorConfig(config, key)
            return cli.LogMapperCommandResponse(
                True, json.dumps(getJsonMonitorColnames(monitorConfig)))

        if self.arg1 == 'logRecords' and len(self.args) == 4:
            key = self.args[1]
            readerConfig = cfg.loadReaderConfig(config, key)
            start = datetime.datetime.strptime(self.args[2], '%Y-%m-%dT%H:%M')
            end = datetime.datetime.strptime(self.args[3], '%Y-%m-%dT%H:%M')
            return cli.LogMapperCommandResponse(
                True,
                json.dumps(getLogEventsWithRemoteCall(readerConfig, start,
                                                      end)))

        if self.arg1 == 'logkeysEvents' and len(self.args) == 3:
            category = cat.LogEventCategories[self.args[1]]
            key = self.args[2]
            readerConfig = cfg.loadReaderConfig(config, key)
            return cli.LogMapperCommandResponse(
                True, json.dumps(getLogNodesByCategory(readerConfig,
                                                       category)))

        return cli.LogMapperCommandResponse(False, "Invalid option")