コード例 #1
0
ファイル: emulator.py プロジェクト: pombredanne/rucio
def observe_gearman_queue(cfg, stop_event):
    acs = {}
    for s in cfg['gearman']:
        acs[s.split(':')[0]] = GearmanAdminClient([s])
    cs = Client(host=cfg['carbon']['CARBON_SERVER'], port=cfg['carbon']['CARBON_PORT'], prefix=cfg['carbon']['USER_SCOPE'])
    count = 0
    pid = os.getpid()
    while stop_event.is_set() is False:
        queue = 0
        try:
            for s in acs:
                try:
                    stat = acs[s].get_status()
                    for task in stat:
                        if task['task'] == 'execute_uc':
                            queue += task['queued']
                            cs.gauge('emulator.counts.gearman.%s' % s, task['queued'])
                except Exception:
                    print '= ERROR: Failed to get stats from %s' % s
                    cs.gauge('emulator.counts.gearman.%s' % s, 0)
            cs.gauge('emulator.counts.files.emulator', get_open_fds())
            if not count % 10:
                print '= (PID: %s [%s]) Gearman-Queue size: %s' % (pid, time.strftime('%H:%M:%S', time.localtime()), queue)
            count += 1
        except Exception:
            print traceback.format_exc()
        try:
            stop_event.wait(10.0)
        except KeyboardInterrupt:
            pass
    print '= Stopping queue observer ... OK'
コード例 #2
0
ファイル: meter_read.py プロジェクト: aequitas/meter_read
def main():
    '''Main entry point for the meter_read CLI.'''
    args = rcfile('meter_read', docopt(__doc__, version=__version__))

    logging.basicConfig()
    log = logging.getLogger(__name__)

    if args['verbose']:
        log.setLevel(logging.DEBUG)

    sc = Client(args['addr'], args['port'])

    re_valid = re.compile(args['valid'])
    re_timer = re.compile(args['timer'])

    aliasses = json.loads(args.get('aliasses', '{}'))

    log.debug('found aliasses: %s' % aliasses)

    log.debug('start reading %s' % args['dev'])
    s = serial.Serial(port=args['dev'], baudrate=args['baud'])
    while True:
        line = s.readline()
        match = re_valid.match(line)
        if match:
            check, name, value = match.groups()
            name = aliasses.get(name, name)
            log.debug("{0} {1}".format(name, value))
            # send to statsd
            if re_timer.match(line):
                sc.timing(name, float(value))
            else:
                sc.gauge(name, float(value))
        else:
            log.debug('error %s' % unicode(line, errors='ignore'))
            sc.increment('error')
コード例 #3
0
ファイル: statsd_test.py プロジェクト: diogobaeder/pystatsd
#!/usr/bin/env python

import time
from multiprocessing import Process

from pystatsd import Client, Server


def worker():
    srvr = Server(debug=True, flush_interval=500)
    srvr.serve()


p = Process(target=worker, daemon=False)
p.start()
time.sleep(1)


sc = Client('localhost', 8125)
sc.timing('python_test.time', 500)
sc.increment('python_test.inc_int')
sc.decrement('python_test.decr_int')
sc.gauge('python_test.gauge', 42)


time.sleep(2)
p.terminate()
コード例 #4
0
ファイル: statsd_test.py プロジェクト: RepositPower/pystatsd
#!/usr/bin/env python

from pystatsd import Client, Server

sc = Client("localhost", 8125)

sc.timing("python_test.time", 500)
sc.increment("python_test.inc_int")
sc.decrement("python_test.decr_int")
sc.gauge("python_test.gauge", 42)

srvr = Server(debug=True)
srvr.serve()
コード例 #5
0
        return "<pystatsd.statsd.Client addr=%s prefix=%s>" % (self.addr,
                                                               self.prefix)


########NEW FILE########
__FILENAME__ = statsd_test
#!/usr/bin/env python

from pystatsd import Client, Server

sc = Client('localhost', 8125)

sc.timing('python_test.time', 500)
sc.increment('python_test.inc_int')
sc.decrement('python_test.decr_int')
sc.gauge('python_test.gauge', 42)

srvr = Server(debug=True)
srvr.serve()

########NEW FILE########
__FILENAME__ = client
import time
import unittest
import mock
import socket
import sys

from pystatsd.statsd import Client

if sys.version_info[0] < 3: