args.points_per_batch < args.series_per_batch:
        exit('points-per-batch must be equal or greater than series-per-batch')

    if args.max_parallel < 1:
        exit('max-parallel must be > 0')

    try:
        if datetime.datetime.strptime(args.start_date,
                                      '%Y-%m-%d') >= datetime.datetime.today():
            exit('start date must be a date before today.')
    except Exception:
        exit('invalid date: {}'.format(args.start_date))

    setup_logger(args)
    signal.signal(signal.SIGINT, signal_handler)

    siri = SiriDBClient(username=args.user,
                        password=args.password,
                        dbname=args.dbname,
                        hostlist=[[s.strip() for s in server.split(':')]
                                  for server in args.servers.split(',')])

    loop = asyncio.get_event_loop()
    loop.run_until_complete(dump_data(siri, args))

    total_time = time.time() - start_time
    logging.info('total time: {:.3f} seconds, '
                 'processed: {}, '
                 'failed: {}'.format(total_time, total_processed,
                                     total_failed))
            args.user = prompt('Username: '******'Password: '******'Database name: ')
    except KeyboardInterrupt:
        signal_handler()

    try:
        hostlist = get_hostlist(args.servers)
    except ValueError:
        sys.exit('Invalid servers, expecting something like: '
                 'server1.local:9000,[::1]:9000 ...')

    cluster = SiriDBClient(username=args.user,
                           password=args.password,
                           dbname=args.dbname,
                           hostlist=hostlist,
                           keepalive=True)

    loop = asyncio.get_event_loop()

    try:
        loop.run_until_complete(prompt_loop(cluster))
    except:
        pass

    sys.exit(0)
    parser.add_argument(
        '-n',
        '--number-of-samples',
        type=int,
        default=0,
        help='number of samples. (when 0 the script will run forever)')

    parser.add_argument('-i',
                        '--interval',
                        type=int,
                        default=5,
                        help='interval')

    parser.add_argument('-t',
                        '--time-precision',
                        default='s',
                        choices=['s', 'ms', 'us', 'ns'],
                        help='time precision')

    args = parser.parse_args()

    cluster = SiriDBClient(
        username=args.user,
        password=args.password,
        dbname=args.database,
        hostlist=[server.split(':') for server in args.servers.split(',')])

    loop = asyncio.get_event_loop()
    loop.run_until_complete(monitor(cluster, args))
Exemple #4
0
                           maintainer=__maintainer__,
                           email=__email__))

    config = configparser.RawConfigParser()

    with open(args.config, 'r', encoding='utf-8') as f:
        config.read_file(f)

    try:
        config.hostlist = [(server.strip(), int(port)) for server, port in [
            s.split(':') for s in re.split(r'\s+|\s*,\s*',
                                           config.get('Database', 'servers'))
        ]]

    except ValueError:
        sys.exit('Invalid servers in configuration file "{}", '
                 'expecting something like: '
                 'server1.local:9000,server2.local:9000 ...'.format(
                     args.config))

    siri = SiriDBClient(username=config.get('Database', 'user'),
                        password=config.get('Database', 'password'),
                        dbname=config.get('Database', 'dbname'),
                        hostlist=config.hostlist,
                        keepalive=True)

    app = App(config=config, siri=siri, debug_mode=args.debug)
    app.start()
    # bye
    sys.exit(0)
Exemple #5
0
import asyncio
import json
import time
import random
from siridb.connector import SiriDBClient


async def example(siri):
    # Start connecting to siridb.
    # .connect() returns a list of all connections referring to the supplied
    # hostlist. The list can contain exceptions in case a connection could not
    # be made.
    await siri.connect()

    try:
        await siri.insert({'hub_test1': [[1560350480175, 1]]})
    finally:
        # Close all siridb connections.
        siri.close()


siri = SiriDBClient(
    username='******',
    password='******',
    dbname='testdata_1',
    hostlist=[('localhost', 9000)],  # Multiple connections are supported
    keepalive=True)

loop = asyncio.get_event_loop()
loop.run_until_complete(example(siri))