Beispiel #1
0
def metric(jobs, options):
    log.info('starting')

    db = dbRedis(options)

    context = zmq.Context()
    router  = context.socket(zmq.ROUTER)
    poller  = zmq.Poller()
    poller.register(router, zmq.POLLIN)

    remoteID = None
    sequence = 0

    while True:
        if remoteID is None:
            for serverID in db.lrange(ID_METRICS_WORKER, 0, -1):
                if not db.sismember('%s:inactive' % ID_METRICS_WORKER, serverID):
                    remoteID = serverID
                    address  = remoteID.replace('%s:' % ID_METRICS_WORKER, '')

                    if ':' not in address:
                        address = '%s:%s' % (address, PORT_PULSE)
                    address = 'tcp://%s' % address

                    log.debug('connecting to server %s' % address)

                    router.connect(address)
                    time.sleep(0.1)

        try:
            job = jobs.get(False)
        except Empty:
            job = None

        if job is not None:
            msg = json.dumps(job)
            sequence += 1
            payload   = [remoteID, str(sequence), 'job', msg]

            if options.debug:
                log.debug('send %s %d chars [%s]' % (remoteID, len(msg), msg[:42]))

            router.send_multipart(payload)

        try:
            items = dict(poller.poll(100))
        except:
            break

        if router in items:
            reply = router.recv_multipart()

    log.info('done')
Beispiel #2
0
    initLogs(options, chatty=False)

    if options.cachefile is None:
        options.cachefile = os.path.join(options.appPath, 'kittenherder_seen.dat')

    if options.kittens is None:
        log.info('kitten list not specified, defaulting to %s' % urlNeedingReboot)
        options.kittens = urlNeedingReboot

    if options.filter is not None:
        reFilter = re.compile(options.filterbase % options.filter)
    else:
        reFilter = None

    db = dbRedis(options)

    log.info('Starting')

    initKeystore(options)

    if options.verbose:
        log.info('retrieving list of kittens to wrangle')

    seenCache = loadCache(options.cachefile)
    kittens   = loadKittenList(options)

    if len(kittens) > 0:
        results = []
        workers = []
        try:
Beispiel #3
0
    for host, weight in swtKittens[:10]:
        h.write(kTableDetail % kittens[host])
    h.write(kTableFooter)

    h.close()


_defaultOptions = {
    'config': ('-c', '--config', None, 'Configuration file'),
    'debug': ('-d', '--debug', True, 'Enable Debug', 'b'),
    'logpath':
    ('-l', '--logpath', None, 'Path where log file is to be written'),
    'redis': ('-r', '--redis', 'localhost:6379', 'Redis connection string'),
    'redisdb': ('', '--redisdb', '8', 'Redis database'),
}

if __name__ == '__main__':
    options = initOptions(params=_defaultOptions)
    initLogs(options)

    log.info('Starting')

    log.info('Connecting to datastore')
    db = dbRedis(options)

    if db.ping():
        loadSAdata()
        indexPage(db)

    log.info('done')