Ejemplo n.º 1
0
def fetch_dp(uid, datapoint):
    """Function for handling /fetch/agent/<uid>/<datapoint> route.

    Args:
        uid: Unique Identifier of an Infoset Agent

    Returns:
        JSON response of all data under specific datapoint

    """ 
    # TODO implement start and stop times
    config = infoset.config['GLOBAL_CONFIG']
    data = GetIDX(datapoint, config)
    data_values = data.everything()
    # Gets all associated datapoints
    """
    x_axis = []
    y_axis = []
    for key, value in data_values.items():
        x_axis.append(key)
        y_axis.append(value)
    np_x_axis = np.asarray(x_axis)
    np_y_axis = np.asarray(y_axis)
    plt.plot(np_x_axis, np_y_axis)
    plt.savefig("/home/proxima/public_html/graph.png")
    """
    return jsonify(data_values)
Ejemplo n.º 2
0
def fetch_dp(uid, datapoint):
    """Function for handling /fetch/agent/<uid>/<datapoint> route.

    Args:
        uid: Unique Identifier of an Infoset Agent

    Returns:
        JSON response of all data under specific datapoint

    """
    # TODO implement start and stop times
    data = GetIDX(datapoint)
    data_values = data.everything()

    # Return
    return jsonify(data_values)
Ejemplo n.º 3
0
def fetch_graph(uid, datapoint):
    """Create graph.

    Args:
        uid: Agent uid
        datpoint: Datapoint idx

    Returns:
        None

    """
    # Getting start and stop parameters from url
    start = request.args.get('start')
    stop = request.args.get('stop')

    # Get data as dict
    datapointer = GetIDX(datapoint, start=start, stop=stop)
    data = datapointer.chart_everything()

    # Return
    return jsonify(data)
Ejemplo n.º 4
0
def fetch_graph_stacked(uid, stack_type):
    """Process stacked charts.

    Args:
        uid: Agent uid
        datpoint: Datapoint idx

    Returns:
        Image of Stacked Chart

    """
    # Define key variables
    # We are only interested in the infoset server host idx for now.
    idx_host = 1
    labels = {}

    # Define label values
    labels['cpu'] = [
        'cpu_times_percent_iowait',
        'cpu_times_percent_irq',
        'cpu_times_percent_ctx_switches',
        'cpu_times_percent_syscalls',
        'cpu_times_percent_interrupts',
        'cpu_times_percent_soft_interrupts',
        'cpu_times_percent_softirq',
        'cpu_times_percent_steal',
        'cpu_times_percent_user',
        'cpu_times_percent_nice',
        'cpu_times_percent_system',
        'cpu_times_percent_idle',
        'cpu_times_percent_guest',
        'cpu_times_percent_guest_nice'
    ]
    labels['memory'] = [
        'memory_buffers',
        'memory_cached',
        'memory_shared',
        'memory_available',
        'memory_free'
    ]
    labels['load'] = [
        'load_average_01min',
        'load_average_05min',
        'load_average_15min'
    ]
    labels['network'] = [
        'network_bytes_recv',
        'network_bytes_sent'
    ]

    # Get Agent data
    idx_agent = db_agent.GetUID(uid).idx()

    # Determine what kind of stacked chart to make
    # Memory, Load, Bytes In/Out, CPU
    if 'memory' in stack_type:
        # Do memory
        datapoint_list = _datapoint_labels(
            idx_host, idx_agent, labels['memory'])
    elif 'cpu' in stack_type:
        # Do cpu
        datapoint_list = _datapoint_labels(
            idx_host, idx_agent, labels['cpu'])
    elif 'load' in stack_type:
        # Do load
        datapoint_list = _datapoint_labels(
            idx_host, idx_agent, labels['load'])
    elif 'network' in stack_type:
        # Do network
        datapoint_list = _datapoint_labels(
            idx_host, idx_agent, labels['network'])
    elif 'disk' in stack_type:
        # Do disk
        pass

    values = []
    for datapoint in datapoint_list:
        get_idx = GetIDX(datapoint)
        data = get_idx.chart_everything()
        values.extend(data)

    return jsonify(values)