Ejemplo n.º 1
0
def json_chart_data_db(request, dbid):
    host_id, instance_id = get_request_ids(request)
    start, end = parse_start_end(request)

    data = getstatdata_sample(request, "db", start, end, dbid=dbid)
    data = convert_decimal_to_float(data)
    return jsonify(dict(data=data))
Ejemplo n.º 2
0
def json_data(request, dbid, queryid=None, userid=None):
    host_id, instance_id = get_request_ids(request)
    start, end = parse_start_end(request)

    query = text("""
        SELECT DISTINCT(datname)
        FROM statements.statements
        WHERE dbid = :dbid
        AND agent_address = :agent_address
        AND agent_port = :agent_port;
    """)
    datname = request.db_session.execute(
        query,
        dict(agent_address=request.instance.agent_address,
             agent_port=request.instance.agent_port,
             dbid=dbid)).fetchone()[0]

    params = dict(agent_address=request.instance.agent_address,
                  agent_port=request.instance.agent_port,
                  dbid=dbid,
                  start=start,
                  end=end)

    query = BASE_QUERY_STATDATA_DATABASE
    queryidfilter = ''
    if queryid is not None and userid is not None:
        queryidfilter = 'AND queryid = :queryid AND userid = :userid'
        params.update(dict(queryid=queryid, userid=userid))
    query = query.format(**dict(queryidfilter=queryidfilter))

    statements = request.db_session.execute(query, params).fetchall()
    statements = [dict(statement) for statement in statements]
    return jsonify(dict(datname=datname, data=statements))
Ejemplo n.º 3
0
def json_data_instance(request):
    host_id, instance_id = get_request_ids(request)
    start, end = parse_start_end(request)

    base_query = BASE_QUERY_STATDATA
    diffs = get_diffs_forstatdata()
    query = (select([
        column("datname"),
        column("dbid"),
    ] + diffs).select_from(base_query).group_by(
        column("dbid"), column("datname")).having(
            func.max(column("calls")) - func.min(column("calls")) > 0))

    statements = request.db_session.execute(
        query,
        dict(agent_address=request.instance.agent_address,
             agent_port=request.instance.agent_port,
             start=start,
             end=end)) \
        .fetchall()
    statements = [dict(statement) for statement in statements]

    metas = request.db_session.execute(
        METAS_QUERY,
        dict(agent_address=request.instance.agent_address,
             agent_port=request.instance.agent_port)).fetchone()
    metas = dict(metas) if metas is not None else None
    return jsonify(dict(data=statements, metas=metas))
Ejemplo n.º 4
0
def json_chart_data_query(request, dbid, queryid, userid):
    host_id, instance_id = get_request_ids(request)
    start, end = parse_start_end(request)

    data = getstatdata_sample(request,
                              "query",
                              start,
                              end,
                              dbid=dbid,
                              queryid=queryid,
                              userid=userid)
    return jsonify(dict(data=data))
Ejemplo n.º 5
0
def json_chart_data_instance(request):
    host_id, instance_id = get_request_ids(request)
    start, end = parse_start_end(request)

    data = getstatdata_sample(request, "instance", start, end)
    return jsonify(dict(data=data))