Exemplo n.º 1
0
async def _run_test(info):
    kafka_server = kafka.Server(**read_json_file(info.kafka_conn))
    dsn = db.Dsn(**read_json_file(info.db_conn), **read_json_file(info.db))

    await db.recreate_db(info.db_conn, info.admin, info.db)
    record_task = asyncio.create_task(
        recorder.collect_data(
            server=kafka_server,
            dsn=dsn,
            is_stop_loop=lambda: True,
        ))
    await asyncio.sleep(1)
    url = "https://google.com"
    await monitor.monitor_one_site(
        server=kafka_server,
        url=url,
        interval=1,
        match=r'html',
        is_stop_loop=lambda: True,
    )
    await record_task
    data = []
    async with db.connection_context(dsn) as connection:
        site_state = db.SiteState(connection)
        async for record in site_state.gen_url_state(info.url):
            data.append(record)
    assert len(data) == 1
    v = data[0]
    assert v['url'] == url
    assert v['latency'] > 0
    assert v['http_code'] == 200
    print('Got', data)
Exemplo n.º 2
0
def main():
    """Execute CLI app for site status recorder."""
    args = _parse_args()
    asyncio.run(
        collect_data(
            server=kafka.Server(**read_json_file(args.kafka_conn)),
            dsn=db.Dsn(**read_json_file(args.db_conn),
                       **read_json_file(args.db)),
        ))
    sys.exit(0)
Exemplo n.º 3
0
def main():
    """Execute CLI app for single site monitoring."""
    args = _parse_args()
    asyncio.run(monitor_one_site(
        server=kafka.Server(**read_json_file(args.kafka_conn)),
        url=args.url,
        interval=args.interval,
        match=args.match,
    ))
Exemplo n.º 4
0
async def _get_url_state(info):
    dsn = Dsn(**read_json_file(info.db_conn), **read_json_file(info.db))
    async with connection_context(dsn) as connection:
        site_state = SiteState(connection)
        async for record in site_state.gen_url_state(info.url):
            print(record)
Exemplo n.º 5
0
async def recreate_db(db_conn, admin, db):
    """Re-creates database and user from scratch."""
    dsn = Dsn(**read_json_file(db_conn), **read_json_file(admin))
    db = Db(**read_json_file(db))
    async with connection_context(dsn) as connection:
        await db.recreate(connection)