def iso_map_dynamic(current_value_list, label, transition, closest_monitor_range, action_status): dynamic_all_values.append(current_value_list) write_as_template(dynamic_all_values, violation_position) if(len(dynamic_all_values) > 12): X = numpy.array(dynamic_all_values) # print "Actual Values: ",X #For all the dimensions normalise the value range between 0 and 1 #use ceiling function to remove small noise X = util.scale(X) util.compute_utilization(util.scale_list(current_value_list)) #n_neighbors = 10 #Y = manifold.Isomap(n_neighbors, 2, max_iter= 4000).fit_transform(X) Y = manifold.MDS().fit_transform(X) #Y = manifold.LocallyLinearEmbedding().fit_transform(X) old_values = Y[:-1] new_value = Y[-1:] plot.animated_plot(old_values, new_value, violation_position, action_status) if closest_monitor_range: closest_range_position.append(len(dynamic_all_values) -1) # If transition, remove all the values until the closest_range_position # remove matching violation_position. It is important to do this before violation position is included inorder to feed in the updated (correct) # position of dynamic_values to violation_position. if transition: # print "!!!!!!!!!!Transition detected!!!!!!!!!! " # print "Closest Range positions (before): " ,closest_range_position # print "Violation positions (before) ", violation_position # print "Length All Values (before): ", len(dynamic_all_values) # reversed is important. Remove elements at the end first to avoid messing up index in subsequent deletions. if len(closest_range_position) >1: for position in reversed(xrange(closest_range_position[-2]+1, closest_range_position[-1])): print "Deleting element in position: ", position del dynamic_all_values[position] if position in violation_position: violation_position.remove(position) #closest_Range_position[-1] does not anymore hold the right position. update the position by number of elements deleted. closest_range_position[-1] = closest_range_position[-1] - abs(closest_range_position[-2]+1 - closest_range_position[-1]) # print "Length All Values (after): ", len(dynamic_all_values) # print "Violation positions (after) ", violation_position # print "Closest Range positions (after): " ,closest_range_position # Append the position of the violation only after plotting # inorder to plot the current value as current point instead of a violation if label: violation_position.append(len(dynamic_all_values)-1)
def monitorStore(processing_time): """ Get monitored information find timestamp read violation-file if violation happened in the last period, attach violation label send to mds """ # commented to use psutil system info system_info = systeminfo.get_all_info() global previous_scaled_monitored_list global previous_violation_label global learn_distance system_info = {} violation_label = False transition = False closest_monitor_range = False application_timestamp = None qos_metric = None monitored_timestamp = util.get_current_system_timestamp() info_dict, current_monitored_list = sliverinfo.collectAllData() system_info.update(info_dict) file_values = read_violation_file() if file_values and len(file_values) ==2 : application_timestamp, qos_metric = file_values print "Total no. of Frames Encoded: ", qos_metric # print "Monitored Timestamp: ", monitored_timestamp # print "QoS Metric Timestamp: ", application_timestamp #Check if the current value falls within the range of monitor. The closest_monitor_range is the first # monitored value closest to the application timestamp if application_timestamp and abs(application_timestamp - monitored_timestamp) < config.TIMEPERIOD + processing_time : closest_monitor_range = True if qos_metric: if config.latency_app is not 'vlc': violation_label = check_violation(qos_metric) else: violation_label = vlc.qos.check_violation(qos_metric, application_timestamp) transition = check_transition(violation_label) # If an action has been taken, compare the measurement vectors to decide when to revoke the action if action_status: scaled_monitored_list = util.scale_list(current_monitored_list) if previous_scaled_monitored_list: dist = distance.calculate_distance_list(scaled_monitored_list, previous_scaled_monitored_list) print "Distance: ", dist if dist and dist > learn_distance: #revoke action and reset previous_monitored_list to None to start afresh revoke_action() previous_scaled_monitored_list = None else: previous_scaled_monitored_list = scaled_monitored_list #Transition check over. Safe to update previous violation label. if violation_label: previous_violation_label= True print "HIT!!! Label as Violation" # Pause the batch application. take_action() else: previous_violation_label = False mds.iso_map_dynamic(current_monitored_list, violation_label, transition, closest_monitor_range, action_status) end_timestamp = util.get_current_system_timestamp() processing_time = end_timestamp - monitored_timestamp #print "Processing Time: ", processing_time return processing_time