Ejemplo n.º 1
0
def add_fake_data():
    """ Adds data to the database for testing purposes. Module flask_monitoringdashboard must be imported locally. """
    from flask_monitoringdashboard.database import session_scope, Request, Endpoint, Outlier
    from flask_monitoringdashboard import config

    # Add requests
    with session_scope() as db_session:
        for i in range(len(REQUESTS)):
            call = Request(id=REQUEST_IDS[i],
                           endpoint_id=ENDPOINT_ID,
                           duration=REQUESTS[i],
                           version_requested=config.version,
                           time_requested=TIMES[i],
                           group_by=GROUP_BY,
                           ip=IP)
            db_session.add(call)

        # Add endpoint
        db_session.add(
            Endpoint(id=ENDPOINT_ID,
                     name=NAME,
                     monitor_level=1,
                     time_added=datetime.datetime.utcnow(),
                     version_added=config.version,
                     last_requested=TIMES[0]))

        # Add Outliers
        for i in range(OUTLIER_COUNT):
            db_session.add(
                Outlier(request_id=i + 1,
                        cpu_percent='[%d, %d, %d, %d]' %
                        (i, i + 1, i + 2, i + 3)))
Ejemplo n.º 2
0
def move_function_calls(old_connection):
    function_calls = old_connection.execute("select * from {}".format(TABLES[1]))
    requests = []
    with session_scope() as db_session:
        populate_endpoint_dict(db_session)
        for fc in function_calls:
            request = Request(endpoint_id=endpoint_dict[fc['endpoint']], duration=fc['execution_time'],
                              time_requested=parse(fc['time']), version_requested=fc['version'],
                              group_by=fc['group_by'], ip=fc['ip'])
            requests.append(request)
        db_session.bulk_save_objects(requests)
Ejemplo n.º 3
0
def add_request(db_session, duration, endpoint_id, ip):
    """ Adds a request to the database. Returns the id.
    :param db_session: session for the database
    :param duration: duration of the request
    :param endpoint_id: id of the endpoint
    :param ip: IP address of the requester
    :return the id of the request after it was stored in the database
    """
    request = Request(endpoint_id=endpoint_id, duration=duration, ip=ip)
    db_session.add(request)
    db_session.flush()
    return request.id
Ejemplo n.º 4
0
def add_request(db_session, duration, endpoint_id, ip, group_by, status_code):
    """ Adds a request to the database. Returns the id.
    :param status_code:  status code of the request
    :param db_session: session for the database
    :param duration: duration of the request
    :param endpoint_id: id of the endpoint
    :param ip: IP address of the requester
    :param group_by: a criteria by which the requests can be grouped
    :return the id of the request after it was stored in the database
    """
    request = Request(endpoint_id=endpoint_id, duration=duration, ip=ip, group_by=group_by, status_code=status_code)
    db_session.add(request)
    db_session.flush()
    return request.id