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)
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)