示例#1
0
def main(opts):
    config = ConfigParser()
    config.optionxform=str
    if opts.ini == '':
        print 'ERROR: You must specify a valid ini file path. Use -h for help'
        return 
    if not os.path.isfile(opts.ini):
        print 'ERROR: Specified ini file is not found' 
        return 
    
    config.read(opts.ini)
    utils.setOptions(opts.options, config)
    print utils.showOptions(config, ['General', 'DB', 'Load', 'Query'])
    
    # Set logging 
    logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', datefmt=utils.DEFAULT_TIMEFORMAT, level=getattr(logging, config.get('General','LogLevel')))
    
    if not opts.show:        
        loadermodule = config.get('General','Loader')
        loadername = loadermodule.split('.')[-1]
        
        exec 'from ' + loadermodule + ' import ' + loadername
        loader = getattr(sys.modules[loadermodule], loadername)(config)
        # Loads data into DB
        loader.run()
示例#2
0
def main(opts):
    config = ConfigParser()
    config.optionxform = str
    if opts.ini == '':
        print 'ERROR: You must specify a valid ini file path.'
        return
    if not os.path.isfile(opts.ini):
        print 'ERROR: Specified ini file is not found'
        return

    config.read(opts.ini)
    utils.setOptions(opts.options, config)
    print utils.showOptions(config, ['General', 'DB', 'Load', 'Query'])

    # Set logging
    logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s',
                        datefmt=utils.DEFAULT_TIMEFORMAT,
                        level=getattr(logging,
                                      config.get('General', 'LogLevel')))

    if not opts.show:
        queriermodule = config.get('General', 'Querier')
        queriername = queriermodule.split('.')[-1]

        exec 'from ' + queriermodule + ' import ' + queriername
        querier = getattr(sys.modules[queriermodule], queriername)(config)

        # Run the queries
        stats = querier.run()

        h = ('#Query', 'Points', 'Waste', 'Time', 'CPU', 'MEM')
        rows = []
        for stat in stats:
            (queryName, qTime, qResult, qCPU, qMEM) = stat
            if qTime == None or qTime == '-':
                qTime = '-'
            else:
                qTime = '%.2f' % qTime
            if qCPU == None or qCPU == '-':
                qCPU = '-'
                qMEM = '-'
            else:
                qCPU = '%.2f' % qCPU
                qMEM = '%.2f' % qMEM
            rows.append((str(queryName), str(qResult), '-', qTime, qCPU, qMEM))

        outputFile = open(utils.RESULTS_FILE_NAME, 'w')
        outputFile.write(tabulate(rows, headers=h) + '\n')
        outputFile.close()
        logging.info('Check results in ' +
                     os.path.abspath(utils.RESULTS_FILE_NAME))
示例#3
0
def main(opts):
    config = ConfigParser()
    config.optionxform=str
    if opts.ini == '':
        print 'ERROR: You must specify a valid ini file path.'
        return
    if not os.path.isfile(opts.ini):
        print 'ERROR: Specified ini file is not found' 
        return 

    config.read(opts.ini)
    utils.setOptions(opts.options, config)
    print utils.showOptions(config, ['General', 'DB', 'Load', 'Query'])
        
    # Set logging 
    logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', datefmt=utils.DEFAULT_TIMEFORMAT, level=getattr(logging, config.get('General','LogLevel')))
    
    if not opts.show:
        queriermodule = config.get('General','Querier')
        queriername = queriermodule.split('.')[-1]
        
        exec 'from ' + queriermodule + ' import ' + queriername
        querier = getattr(sys.modules[queriermodule], queriername)(config)

        # Run the queries
        stats = querier.run()
        
        h = ('#Query','Points','Waste','Time','CPU','MEM')
        rows = []
        for stat in stats:
            (queryName, qTime, qResult, qCPU, qMEM) = stat
            if qTime == None or qTime == '-':
                qTime = '-'
            else:
                qTime = '%.2f'%qTime
            if qCPU == None or qCPU == '-':
                qCPU = '-'
                qMEM = '-'
            else:
                qCPU = '%.2f'%qCPU
                qMEM = '%.2f'%qMEM
            rows.append((str(queryName),str(qResult),'-',qTime,qCPU,qMEM))        
        
        outputFile = open(utils.RESULTS_FILE_NAME,'w')
        outputFile.write(tabulate(rows, headers=h) + '\n')
        outputFile.close()
        logging.info('Check results in ' + os.path.abspath(utils.RESULTS_FILE_NAME))