Exemplo n.º 1
0
def worker(jobQueue, graphite, db):
    log.info('starting')

    metrics = Metric(graphite, db)

    while True:
        try:
            job = jobQueue.get(False)
        except Empty:
            job = None

        if job is not None:
            try:
                jobs = json.loads(job)

                for item in jobs:
                    metric, data = item
                    if metric == METRICS_COUNT:
                        group = data[0]
                        key = data[1]

                        metrics.count('count')
                        metrics.count(group)
                        metrics.count('%s.%s' % (group, key))

                    elif metric == METRICS_LIST:
                        metrics.count('list')
                        if len(data) == 2:
                            key = data[0]
                            value = data[1]
                            db.rpush(key, value)

                    elif metric == METRICS_SET:
                        metrics.count('set')
                        if len(data) == 2:
                            key = data[0]
                            value = data[1]
                            db.sadd(key, value)

                    elif metric == METRICS_HASH:
                        metrics.count('hash')
                        if len(data) == 3:
                            hash = data[0]
                            key = data[1]
                            value = data[2]
                            db.hset(hash, key, value)
                            db.sadd('metrics.hashes', hash)
                    elif metric == METRICS_RAW:
                        metrics.carbon('%s %d %s\n' %
                                       (data[0], data[1], time.time()))

            except:
                log.error('Error converting incoming job', exc_info=True)

            metrics.check()

    log.info('done')
Exemplo n.º 2
0
def worker(jobQueue, graphite, db):
    log.info('starting')

    metrics = Metric(graphite, db)

    while True:
        try:
            job = jobQueue.get(False)
        except Empty:
            job = None

        if job is not None:
            try:
                jobs = json.loads(job)

                for item in jobs:
                    metric, data = item
                    if metric == METRICS_COUNT:
                        group = data[0]
                        key   = data[1]

                        metrics.count('count')
                        metrics.count(group)
                        metrics.count('%s.%s' % (group, key))

                    elif metric == METRICS_LIST:
                        metrics.count('list')
                        if len(data) == 2:
                            key   = data[0]
                            value = data[1]
                            db.rpush(key, value)

                    elif metric == METRICS_SET:
                        metrics.count('set')
                        if len(data) == 2:
                            key   = data[0]
                            value = data[1]
                            db.sadd(key, value)

                    elif metric == METRICS_HASH:
                        metrics.count('hash')
                        if len(data) == 3:
                            hash  = data[0]
                            key   = data[1]
                            value = data[2]
                            db.hset(hash, key, value)
                            db.sadd('metrics.hashes', hash)
                    elif metric == METRICS_RAW:
                        metrics.carbon('%s %d %s\n' % (data[0], data[1], time.time()))

            except:
                log.error('Error converting incoming job', exc_info=True)

            metrics.check()

    log.info('done')