Beispiel #1
0
async def recv_and_process():
    # this has to be within async func
    socket = ctx.socket(zmq.SUB)
    socket.setsockopt_string(zmq.SUBSCRIBE, '')
    socket.setsockopt_string(zmq.PLAIN_USERNAME, "stats")
    socket.setsockopt_string(zmq.PLAIN_PASSWORD, "test")
    socket.setsockopt(zmq.RECONNECT_IVL, 1000)
    socket.connect("tcp://127.0.0.1:55055")

    sdk_ctx = SystemContext()
    sdk = QSSdk(sdk_ctx)

    feed = sdk.create_ql_feed()

    while True:
        data = await socket.recv_json()
        data['__recv_timestamp'] = int(time.time())

        print(data)
        continue
        sdk.feed_ql(feed, data)
Beispiel #2
0
def collect_ql(configfile):
    """
    Config format

    [serv1]
    port = 1
    ip = 1.2.3.4
    password = 101001

    [serv2]
    ...
    """
    ctx = context.SystemContext()
    sdk = QSSdk(ctx)

    collector_config = ConfigParser()
    collector_config.read(configfile)

    def event_cb(feed, timestamp: int, event: dict):
        event['__recv_timestamp'] = time.time()
        sdk.feed_ql(feed, event)

    async def main():
        tasks = []
        for section in collector_config.sections():
            logger.info("Attaching stats from %s", section)
            feed = sdk.create_ql_feed()
            cb = partial(event_cb, feed)

            ip = collector_config.get(section, 'ip')
            port = collector_config.get(section, 'port')
            pwd = collector_config.get(section, 'password')

            collector = QLStatCollector(ip, port, pwd)
            tasks.append(asyncio.create_task(collector.start(cb)))

        await asyncio.gather(*tasks)

    asyncio.run(main())
Beispiel #3
0
def run_rebuild_db():
    ctx = context.SystemContext()
    sdk = QSSdk(ctx)
    sdk.rebuild_db()
Beispiel #4
0
def delete_match(match_guid):
    ctx = context.SystemContext()
    sdk = QSSdk(ctx)
    sdk.delete_match(match_guid)
Beispiel #5
0
def warehouse_list():
    ctx = context.SystemContext()
    sdk = QSSdk(ctx)
    for item in sdk.warehouse_iter():
        print(item)
Beispiel #6
0
def list_matches():
    ctx = context.SystemContext()
    sdk = QSSdk(ctx)
    for match in sdk.iter_matches():
        print(match)
Beispiel #7
0
def process_q3_log(file_path, mod):
    ctx = context.SystemContext()
    sdk = QSSdk(ctx)

    with open(file_path) as fh:
        sdk.process_q3_log(fh.read(), mod)
Beispiel #8
0
def _sdk():
    return QSSdk(get_sys_ctx())