def start_monitoring_local(self): # monitoring lokal in thread starten if self.monitor is None: self.monitor = Monitoring() self.monitor.start() return True else: return False
def startMon(self): print('Starting Mon') self.monitor = Monitoring(self.mon_controller, '6666', self.exp_path, self.iot, self.edge, self.tcpdump_if, self.tcpdump_port, self.receiver) self.monitor.init() self.monitor.set_consumer_pid(self.consumer_PID) self.monitor.start_components() self.monitor.start_monitoring()
def start(args): if args.setupmode == "QUICK_SETUP_MODE": Monitoring.start_monitoring(f"monitoring/node-monitoring.yml") elif args.setupmode == "PRODUCTION_MODE": print(" PRODUCTION_MODE not supported yet ") sys.exit() else: print( "Invalid setup mode . It should be either QUICK_SETUP_MODE or PRODUCTION_MODE" )
def __init__(self, height, width, num_actions, state_frames, gamma, batch_size=32): self.gamma = gamma self.num_actions = num_actions self.input_var = T.tensor4('inputs') self.target_var = T.vector('targets') self.actions_var = T.matrix() self.input_shared = theano.shared(np.zeros([batch_size, state_frames, height, width]), dtype=theano.tensor.floatX) self.taret_shared = theano.shared(np.zeros([batch_size, 1]), dtype=theano.tensor.floatX) self.actions_shared = theano.shared(np.zeros([batch_size, num_actions]).astype('int32'), dtype=theano.tensor.int32) self.net = get_inference(self.input_var, num_actions, height, width, state_frames) self.prediction = (lasagne.layers.get_output(self.net) * self.actions_var).sum(axis=1) self.error = T.sqr(self.target_var - self.prediction).mean() params = lasagne.layers.get_all_params(self.net, trainable=True) #self.opt = lasagne.updates.rmsprop( # self.error, params, learning_rate=0.0025, epsilon=0.01) #self.opt = lasagne.updates.adagrad( # self.error, params, learning_rate=0.001 #) self.opt = gen_updates_rmsprop(params, T.grad(self.error, params)) self.train_step = theano.function([self.input_var, self.target_var, self.actions_var], self.error, updates=self.opt, allow_input_downcast=True) self.net_fun = theano.function([self.input_var], lasagne.layers.get_output(self.net), allow_input_downcast=True) self.monitor = Monitoring() self.pred_fun = theano.function([self.input_var, self.actions_var], self.prediction, allow_input_downcast=True) self.error_fun = theano.function([self.input_var, self.target_var, self.actions_var], self.error, allow_input_downcast=True)
def __init__(self, height, width, session, num_actions, state_frames, gamma, net_type=1, optimizer=tf.train.AdamOptimizer(1e-6)): self.height = height self.width = width self.session = session self.num_actions = num_actions self.state_frames = state_frames self.gamma = gamma self.opt = optimizer self.train_counter = 0 self.input_pl = tf.placeholder(tf.float32, [None, height, width, state_frames]) self.target_pl = tf.placeholder(tf.float32, [None]) self.actions_pl = tf.placeholder(tf.float32, [None, num_actions]) if net_type == 1: self.network = get_inference(self.input_pl, num_actions, 'main_net') else: self.network = get_inference2(self.input_pl, num_actions, 'main_net') self.prediction = tf.reduce_sum(tf.mul(self.network.output, self.actions_pl), 1) #self.error = tf.reduce_mean(tf.square(self.target_pl - self.prediction)) self.error = tf.square(self.target_pl - self.prediction) self.train_step = self.opt.minimize(self.error) self.session.run([tf.initialize_all_variables()]) #todo: throw that away self.monitor = Monitoring()
async def on_start(self): self.terminate = False self.SUCCESS = False self.verbose = False # Initialization self.beliefs = WorldModel() # B := B0; Initial Beliefs self.goals = self.beliefs.current_world_model.goals self.intentions = self.beliefs.current_world_model.goals # I := I0; Initial Intentions self.htn_planner = HierarchicalTaskNetworkPlanner(self.beliefs) self.perception = Perception(self.beliefs) self.coordination = Coordination(self.beliefs) self.monitoring = Monitoring() self.what, self.why, self.how_well, self.what_else, self.why_failed = "", "", "", "", "" self.plans = [] self.selected_plan = [] self.percept = {} self.action = "" self.start_time = datetime.datetime.now()
def run(self, gen: Generator): #print("********************* %s ********************\n" % (gen,)) for ct in self.controllers: ct.setSLA(self.sla) m = Monitoring(self.window) ct.setMonitoring(m) a = Application(self.sla) s = Simulation(self.horizon, a, gen, m, ct) # print(ct) s.run() self.simulations.append(s) ct.reset()
async def on_start(self): self.terminate = False self.SUCCESS = False self.verbose = False # Initialization self.htn_planner = HierarchicalTaskNetworkPlanner() self.goal = [('transfer_target_object_to_container', 'arm', 'target_object', 'table', 'container')] self.intentions = self.goal # I := I0; Initial Intentions self.beliefs = WorldModel() # B := B0; Initial Beliefs self.monitoring = Monitoring() self.perception = Perception() self.coordination = Coordination() # Disable all 3 coordination switches for testing self.coordination.control.send_requests = True self.coordination.control.center_init = False self.coordination.control.detect_last_position = True self.what, self.why, self.how_well, self.what_else, self.why_failed = "", "", "", "", "" self.plans = [] self.start_time = datetime.datetime.now()
def main(): # global data database = Data() database.debug_flag = False """ test from keyboard input """ #database.debug_flag = True # sensor data data_source = Source(database) lidar_source_thread = threading.Thread( target=data_source.lidar_stream_main) left_cam_source_thread = threading.Thread( target=data_source.left_cam_stream_main) right_cam_source_thread = threading.Thread( target=data_source.right_cam_stream_main) mid_cam_source_thread = threading.Thread( target=data_source.mid_cam_stream_main) lidar_source_thread.start() left_cam_source_thread.start() right_cam_source_thread.start() mid_cam_source_thread.start() # Subroutines monitoring = Monitoring(data_source, database) platform = CarPlatform('COM5', database) # PLEASE CHECK YOUR COMPORT sign_cam = SignCam(data_source, database) planner = MotionPlanner(data_source, database) control = Control(database) monitoring_thread = threading.Thread(target=monitoring.main) platform_thread = threading.Thread(target=platform.main) sign_cam_thread = threading.Thread(target=sign_cam.main) planner_thread = threading.Thread(target=planner.main) control_thread = threading.Thread(target=control.main) monitoring_thread.start() platform_thread.start() sign_cam_thread.start() planner_thread.start() control_thread.start() while True: time.sleep(0.1) if database.is_all_system_stop(): break time.sleep(2) return 0
def run(self, gen: Generator): #print("********************* %s ********************\n" % (gen,)) for ct in self.controllers: ct.setSLA(self.sla) if self.genMonitoring: m = self.genMonitoring(self.window, self.sla) else: m = Monitoring(self.window, self.sla) ct.setMonitoring(m) ct.setGenerator(gen) a = self.app s = Simulation(self.horizon, a, gen, m, ct) # print(ct) s.run() self.simulations.append(s) ct.reset() a.reset()
def __readConfig(self): self._configfile = 'client.ini' self._config = ConfigParser.RawConfigParser() self._config.read(self._configfile) self._monitoring = Monitoring() self._user.name = self._config.get("server", 'username') try: try: self.__TCP_IP = self._config.get("server", 'tcp_ip') except ConfigParser.NoOptionError: self.__TCP_IP = TCP_IP try: self.__TCP_PORT = self._config.getint("server", 'tcp_port') except ConfigParser.NoOptionError: self.__TCP_PORT = TCP_PORT try: self.__BUFFER_SIZE = self._config.getint("server", 'buffer_size') except ConfigParser.NoOptionError: self.__BUFFER_SIZE = BUFFER_SIZE except ConfigParser.NoSectionError: self.__TCP_IP = TCP_IP self.__TCP_PORT = TCP_PORT self.__BUFFER_SIZE = BUFFER_SIZE
from flask import Flask, request from flask_restful import Resource, Api from monitoring import Monitoring app = Flask(__name__) api = Api(app) host = 'debuggerbasedmonitoring.appspot.com' basePath = '/api/v1' monitoring = Monitoring() class Breakpoint(Resource): def get(self, user_id, project_id): ret, content = monitoring.getBreakpoints(user_id, project_id) if not ret: return None, 400 return content, 200 def post(self, user_id, project_id): if request.is_json: body = request.get_json() else: return None, 409 if 'content' not in body: return None, 409 content = body['content'] try: file, line = content.split(':')
def foodSense(): print('Starting Food Sense') # Begin initializing necessary components) fb = Firebase() detect = Detect(fb) monitor = Monitoring(fb) scale = Scale() # Set scale calibration scale.setReferenceUnit(-25.725) scale.reset() scale.tare() ### START DEBUG ### ### END DEBUG ### ### MAIN LOOP ### while True: while monitor.powerOn: print('Power is on') time.sleep(1) while monitor.doorClosed(): print('Door is closed') monitor.checkTemp() time.sleep(1) if monitor.doorOpen(): print('Door was opened') monitor.startDoorTimer() while monitor.doorOpen(): print('Waiting for door to close') monitor.checkDoorTimer() monitor.checkTemp() time.sleep(1) else: print('Door was closed') scale.getWeight() detect.getImage() detect.detectItem() detect.parseResponse(scale.weight) else: pass else: print('Door must be closed on program startup') else: monitor.powerSave() else: pass
class DeepQNetwork(object): def __init__(self, height, width, session, num_actions, state_frames, gamma, net_type=1, optimizer=tf.train.AdamOptimizer(1e-6)): self.height = height self.width = width self.session = session self.num_actions = num_actions self.state_frames = state_frames self.gamma = gamma self.opt = optimizer self.train_counter = 0 self.input_pl = tf.placeholder(tf.float32, [None, height, width, state_frames]) self.target_pl = tf.placeholder(tf.float32, [None]) self.actions_pl = tf.placeholder(tf.float32, [None, num_actions]) if net_type == 1: self.network = get_inference(self.input_pl, num_actions, 'main_net') else: self.network = get_inference2(self.input_pl, num_actions, 'main_net') self.prediction = tf.reduce_sum(tf.mul(self.network.output, self.actions_pl), 1) #self.error = tf.reduce_mean(tf.square(self.target_pl - self.prediction)) self.error = tf.square(self.target_pl - self.prediction) self.train_step = self.opt.minimize(self.error) self.session.run([tf.initialize_all_variables()]) #todo: throw that away self.monitor = Monitoring() def get_best_action(self, example): vals = self.evaluate_network([example.transpose([1, 2, 0])])[0] return np.argmax(vals), vals def train(self, batch): self.train_counter += 1 prepare_batch(batch) batch_size = batch['batch_size'] self.monitor.report_action_start('get_batch') target = self.get_target(batch) self.monitor.report_action_finish('get_batch') actions = np.zeros([batch_size, self.num_actions]) actions[:, list(batch['actions'])] = 1 self.monitor.report_action_start('pred') _, error_val, pred = self.session.run( [self.train_step, self.error, self.prediction], feed_dict={self.target_pl: target, self.actions_pl: actions, self.input_pl: batch['states_1']}) self.monitor.report_action_finish('pred') return error_val.mean() def get_target(self, batch): prepare_batch(batch) batch_size = batch['batch_size'] q_vals = self.evaluate_network(batch['states_2']) best_actions = np.argmax(q_vals, 1) target = np.choose(best_actions, q_vals.T) for i in xrange(batch_size): if batch['terminations'][i]: mul = 0 else: mul = self.gamma target[i] = batch['rewards'][i] + mul * target[i] return target def evaluate_network(self, states_batch): return self.session.run(self.network.output, feed_dict={self.input_pl: states_batch})
from control import Control from car_platform import CarPlatform from monitoring import Monitoring testDT = Data() """ test code 특정 미션 번호에서 시작하도록 함 """ testDT.current_mode = 1 testDS = Source(testDT) car = CarPlatform('COM5', testDT) testMP = MotionPlanner(testDS, testDT) test_control = Control(testDT) monitor = Monitoring(testDS, testDT) lidar_source_thread = threading.Thread(target=testDS.lidar_stream_main) left_cam_source_thread = threading.Thread( target=testDS.left_cam_stream_main) right_cam_source_thread = threading.Thread( target=testDS.right_cam_stream_main) mid_cam_source_thread = threading.Thread(target=testDS.mid_cam_stream_main) planner_thread = threading.Thread(target=testMP.main) control_thread = threading.Thread(target=test_control.main) car_thread = threading.Thread(target=car.main) monitoring_thread = threading.Thread(target=monitor.main) lidar_source_thread.start() planner_thread.start() time.sleep(3)
import sys # The logger logging.basicConfig(format="[%(levelname)s] %(asctime)-15s - %(message)s", level=config.LOG_LEVEL) logger = logging.getLogger('radiovisserver') # Logging to file is handled outside by supvervisord instead of the application itself # fh = FileHandler(filename='radiovis-server.log', mode='a') # fh.setFormatter(Formatter(fmt="[%(levelname)s] %(asctime)-15s - %(message)s")) # logger.addHandler(fh) # Last message by TOPIC LAST_MESSAGES = {} monitoring = Monitoring() monitoring.count("radiovis.global.servers") # Create the class to manage the rabbit connexion rabbitcox = RabbitConnexion(LAST_MESSAGES, monitoring) # Handeler for new stomp clients def stomp_client(socket, address): logger.info('%s:%s: New stomp connection from' % address) # Create a new stomp server s = StompServer(socket, LAST_MESSAGES, rabbitcox, monitoring) monitoring.count("radiovis.global.connections", {"session_id": s.session_id, "ip": s.info_ip + ':' + str(s.info_port) }) # Let rabbitmq send messages to the stomp server
async def request(): async with aiohttp.ClientSession() as session: try: async with session.get('http://127.0.0.1:80') as response: return await response.text() except Exception: return False def request_by_count(count: int): return asyncio.run(asyncio.gather(*[ request() for _ in range(count) ])) if __name__ == '__main__': pidfile = sys.argv[1] request_count = int(sys.argv[2]) monitoring = Monitoring(pidfile) with ThreadPoolExecutor() as executor: future = executor.submit(monitoring.measure_resource, .1) start_time = timer() result = request_by_count(request_count) print(f"Latency: {timer() - start_time}") print(f"Errors: {result.count(False)}") monitoring.stop() print(f"Report: {future.result()}")
def start_monitoring(): monitoring = Monitoring() monitoring.call()
import bottle import json import time from bottle import route, run, request, default_app, template, HTTPError from docopt import docopt from engine import ReconcileEngine from suggest import SuggestEngine from monitoring import Monitoring from config import * reconcile = ReconcileEngine(redis_client) suggest = SuggestEngine(redis_client) monitoring = Monitoring(redis_client) def jsonp(view): def wrapped(*posargs, **kwargs): args = {} # if we access the args via get(), # we can get encoding errors… for k in request.forms: args[k] = getattr(request.forms, k) for k in request.query: args[k] = getattr(request.query, k) callback = args.get('callback') try: result = view(args, *posargs, **kwargs) except (ValueError, AttributeError, KeyError) as e: result = {
def run(self): # Set up LED pin LED = 27 GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(LED, GPIO.OUT) # Initialize objects f = Firebase(self.q) d = Detect(f, self.q) m = Monitoring(f, self.q) s = Scale(self.q) # Set scale calibration s.setReferenceUnit(-25.725) s.reset() s.tare() self.q.put('Ready') # Loop until stop event is set while not self.event.is_set(): # Loop while RPi is on AC power while m.powerOn: # Check if stop has been set if self.event.is_set(): break # Loop while fridge door is closed while m.doorClosed(): if not m.powerOn(): break m.checkTemp() # Check if stop hsa been set if self.event.is_set(): break else: print('Door was opened') self.q.put('Door opened') GPIO.output(LED, True) m.startDoorTimer() while m.doorOpen(): print('Waiting for door to close') m.checkDoorTimer() m.checkTemp() else: print('Door closed') self.q.put('Door closed') s.getWeight() d.getImage() d.detectItem() d.parseResponse(s.weight) s.tare() GPIO.output(LED, False) print('Done') self.q.put('Done') else: m.powerSave() f.close( ) # Firebase app must be closed before we can create another instance
return current_intentions if __name__ == '__main__': terminate = False SUCCESS = False verbose = False # Initialization htn_planner = HierarchicalTaskNetworkPlanner() goal = [('transfer_target_object_to_container', 'arm', 'target_object', 'table', 'container')] intentions = goal # I := I0; Initial Intentions beliefs = WorldModel() # B := B0; Initial Beliefs monitoring = Monitoring() perception = Perception() coordination = Coordination() # Disable all 3 coordination switches for testing coordination.control.send_requests = True coordination.control.center_init = False coordination.control.detect_last_position = True what, why, how_well, what_else, why_failed = "", "", "", "", "" start_time = datetime.datetime.now() """ Agent control loop version 7 (Intention Reconsideration) I := I0; Initial Intentions B := B0; Initial Beliefs while true do get next percept ρ; # OBSERVE the world
def handler(): device_name = argv[1] CURRENT_TIME = str(int(time.time() * 1000)) monitoring = Monitoring() process = monitoring.get_running_process() dimensions = [{ 'Name': 'script', 'Value': process['name'] }, { 'Name': 'device_id', 'Value': device_name }, { 'Name': 'user', 'Value': process['username'] }, { 'Name': 'process_id', 'Value': str(process['pid']) }] common_attributes = {'Dimensions': dimensions, 'Time': CURRENT_TIME} record = { 'cpu_usage': monitoring.get_cpu_usage_pct(), 'cpu_freq': monitoring.get_cpu_frequency(), 'cpu_temp': monitoring.get_cpu_temp(), 'ram_usage': int(monitoring.get_ram_usage() / 1024 / 1024), 'ram_total': int(monitoring.get_ram_total() / 1024 / 1024), } print("\n") # print(dimensions) # print(record) print("\n") # Output current CPU load as a percentage. print('System CPU load is {} %'.format(monitoring.get_cpu_usage_pct())) # Output current CPU frequency in MHz. print('CPU frequency is {} MHz'.format(monitoring.get_cpu_frequency())) # Output current CPU temperature in degrees Celsius print('CPU temperature is {} degC'.format(monitoring.get_cpu_temp())) # Output current RAM usage in MB print('RAM usage is {} MB'.format( int(monitoring.get_ram_usage() / 1024 / 1024))) # Output total RAM in MB print('RAM total is {} MB'.format( int(monitoring.get_ram_total() / 1024 / 1024))) # Output current RAM usage as a percentage. print('RAM usage is {} %'.format(monitoring.get_ram_usage_pct())) session = boto3.Session() write_client = session.client('timestream-write', region_name='eu-west-1') response = write_client.write_records( DatabaseName=DB_NAME, TableName=TABLE_NAME, Records=monitoring.get_write_records(), CommonAttributes=common_attributes) print(response) query_client = session.client('timestream-query', region_name='eu-west-1') query = Query(query_client) print("\n") query.run_query_with_multiple_pages(20)
def setup(args): if args.setupmode == "QUICK_SETUP_MODE": monitor_url_dir = f'https://raw.githubusercontent.com/radixdlt/node-runner/{cli_version()}/monitoring' print(f"Downloading artifacts from {monitor_url_dir}\n") Monitoring.setup_prometheus_yml( f"{monitor_url_dir}/prometheus/prometheus.yml") Monitoring.setup_datasource( f"{monitor_url_dir}/grafana/provisioning/datasources/datasource.yml" ) Monitoring.setup_dashboard( f"{monitor_url_dir}/grafana/provisioning/dashboards/", ["dashboard.yml", "sample-node-dashboard.json"]) Monitoring.setup_monitoring_containers( f"{monitor_url_dir}/node-monitoring.yml") Monitoring.setup_external_volumes() monitoring_file_location = "monitoring/node-monitoring.yml" Monitoring.start_monitoring(f"{monitoring_file_location}") elif args.setupmode == "PRODUCTION_MODE": print(" PRODUCTION_MODE not supported yet ") sys.exit() else: print( "Invalid setup mode . It should be either QUICK_SETUP_MODE or PRODUCTION_MODE" )
def main(): while True: print('Init Monitoring') mevents = Monitoring() mevents.monitoring_events()
class BDIBehaviour(PeriodicBehaviour): async def on_start(self): self.terminate = False self.SUCCESS = False self.verbose = False # Initialization self.beliefs = WorldModel() # B := B0; Initial Beliefs self.goals = self.beliefs.current_world_model.goals self.intentions = self.beliefs.current_world_model.goals # I := I0; Initial Intentions self.htn_planner = HierarchicalTaskNetworkPlanner(self.beliefs) self.perception = Perception(self.beliefs) self.coordination = Coordination(self.beliefs) self.monitoring = Monitoring() self.what, self.why, self.how_well, self.what_else, self.why_failed = "", "", "", "", "" self.plans = [] self.selected_plan = [] self.percept = {} self.action = "" self.start_time = datetime.datetime.now() async def run(self): """ Agent control loop version 7 (Intention Reconsideration) I := I0; Initial Intentions B := B0; Initial Beliefs while true do get next percept ρ; # OBSERVE the world B:= brf(B, ρ); # Belief revision function D: = option(B, I); I := filter(B, D, I); π := plan(B, I); # MEANS_END REASONING while not (empty(π) or succeeded(Ι, Β) or impossible(I, B)) do # Drop impossible or succeeded intentions α := hd(π); # Pop first action execute(α); π := tail(π); get next percept ρ; B:= brf(B, ρ); if reconsider(I, B) then # Meta-level control: explicit decision, to avoid reconsideration cost D := options(B, I); I := filter(B, D, I); end-if if not sound(π, I, B) then # Re-activity, re-plan π := plan(B, I); end-if end-while end-while """ if self.verbose: print(f"--- arm_agent: " f"PeriodicSenderBehaviour running " f"at {datetime.datetime.now().time()}: " f"{self.beliefs.current_world_model.ticks}") # while true do if not self.SUCCESS and not self.terminate and self.beliefs.update_tick( ) < self.beliefs.current_world_model.max_ticks: if len(self.selected_plan) == 0: # msg = Message(to="madks2@temp3rr0r-pc") # Instantiate the message # TODO: place holder for IM # msg.body = "Hello World: " + str(self.counter) # Set the message content # await self.send(msg) # TODO: engrave figures: arm IK, gripper self.percept = self.perception.get_percept( text_engraving=(self.why_failed, self.how_well) ) # get next percept ρ; OBSERVE the world self.beliefs = self.perception.belief_revision( self.beliefs, self.percept) # B:= brf(B, ρ); self.beliefs = self.monitoring.fire_events( self.beliefs, self.percept) self.intentions = self.deliberate( self.beliefs, self.intentions ) # DELIBERATE about what INTENTION to achieve next self.SUCCESS = True if self.intentions == "" else False self.plans = self.htn_planner.get_plans( self.beliefs.current_world_model, self.intentions ) # π := plan(B, I); MEANS_END REASONING if self.plans != False: if len(self.plans) > 0: self.plans.sort( key=len ) # TODO: check why sorting doesn't work on "deeper" levels if self.verbose: print("{}: Plan: {}".format( self.beliefs.current_world_model.tick, self.plans[0])) self.selected_plan = deque( self.plans[0] ) # TODO: Use a "cost function" to evaluate the best plan, not shortest self.why_failed = "" else: self.why_failed = self.htn_planner.failure_reason if self.verbose: print("Plan failure_reason: {}".format( self.why_failed), end=" ") self.how_well = ( self.beliefs.current_world_model.tick, self.beliefs.current_world_model.max_ticks, int((datetime.datetime.now() - self.start_time).total_seconds() * 1000), # milliseconds self.plans) if self.verbose: print("how_well: {}".format(self.how_well)) else: # while not (empty(π) or succeeded(Ι, Β) or impossible(I, B)) do self.action, self.selected_plan = self.selected_plan.popleft( ), self.selected_plan # α := hd(π); π := tail(π); if self.verbose: print("{}: Action: {}".format( self.beliefs.current_world_model.tick, self.action)) self.coordination.execute_action( self.action, self.beliefs.current_world_model) # execute(α); self.what, self.why = self.action, self.intentions self.how_well = ( self.beliefs.current_world_model.tick, self.beliefs.current_world_model.max_ticks, int((datetime.datetime.now() - self.start_time).total_seconds() * 1000), # milliseconds self.selected_plan) self.what_else = self.plans[1] if len( self.plans) > 1 else self.plans[0] if self.verbose: self.print_answers(self.what, self.why, self.how_well, self.what_else) # get next percept ρ; OBSERVE the world # TODO: Don't update target object location, when it is obscured if self.action != ('move_arm_above', 'target_object') and self.action != ( 'move_arm', 'target_object'): self.percept = self.perception.get_percept( text_engraving=(self.what, self.why, self.how_well, self.what_else)) self.beliefs = self.perception.belief_revision( self.beliefs, self.percept) self.beliefs = self.monitoring.fire_events( self.beliefs, self.percept) # TODO: trigger sound percept? if self.action == ('initialize', 'arm'): self.percept = { "initialized": { 'arm': True } } # TODO: post conditions or monitoring self.beliefs = self.perception.belief_revision( self.beliefs, self.percept) # TODO: post conditions self.beliefs = self.monitoring.fire_events( self.beliefs, self.percept) elif self.action == ('move_arm', 'target_object'): self.percept = { "distance": { 'distance_to_gripper': 2.2 } } # TODO: update with monitoring self.beliefs = self.perception.belief_revision( self.beliefs, self.percept) self.beliefs = self.monitoring.fire_events( self.beliefs, self.percept) elif self.action == ('move_arm_above', 'container'): self.percept = { "location": { "target_object": "container" }, "grabbed": { 'target_object': False } } self.beliefs = self.perception.belief_revision( self.beliefs, self.percept) self.beliefs = self.monitoring.fire_events( self.beliefs, self.percept) # if reconsider(I, B) then # D := options(B, I); # I := filter(B, D, I); # if not sound(π, I, B) then # π := plan(B, I) # TODO: Backtracking of action? else: self.done() self.kill() async def on_end(self): print("-- on_end") print("Done.") self.perception.destroy() # stop agent from behaviour await self.agent.stop() # async def _step(self): # TODO: Need? # # the bdi stuff # pass def done(self): print("-- Sender Agent: Done") show_history = True print("Final World model:") print("-- Ticks: {}".format(self.beliefs.current_world_model.tick)) print("-- initialized: {}".format( self.beliefs.current_world_model.initialized)) print("-- location: {}".format( self.beliefs.current_world_model.location)) print("-- grabbed: {}".format( self.beliefs.current_world_model.grabbed)) if show_history: print() print("World model History:") for tick in range(len(self.beliefs.world_model_history)): print("Tick {}:".format(tick)) print("-- initialized: {}".format( self.beliefs.world_model_history[tick].initialized)) print("-- location: {}".format( self.beliefs.world_model_history[tick].location)) print("-- grabbed: {}".format( self.beliefs.world_model_history[tick].grabbed)) print() print("{}!".format("SUCCESS" if self.SUCCESS else "FAIL")) def print_answers(self, what_answer, why_answer, how_well_answer, what_else_answer): print( "Q: What is the robot doing? A: {}\n" "Q: Why is it doing it? A: {}\n" "Q: How well is it doing it? A: {}\n" "Q: What else could it have been doing instead? A: {}".format( what_answer, why_answer, how_well_answer, what_else_answer)) def deliberate(self, current_beliefs, current_intentions): """ Decide WHAT sate of affairs you want to achieve. :param current_beliefs: WordModel instance, the world model, information about the world. :param current_intentions: List of tuples, tasks that the agent has COMMITTED to accomplish. :return: List of tuples, filtered intentions that the agent COMMITS to accomplish. """ # 1. Option Generation: The agent generates a set of possible alternatives. current_desires = current_intentions # TODO: D := option(B, I); # 2. Filtering: Agent chooses between competing alternatives and commits to achieving them. current_intentions = self.filter_intentions( current_beliefs, current_desires, current_intentions) # I := filter(B, D, I); return current_intentions def filter_intentions(self, current_beliefs, current_desires, current_intentions): """ Choose between competing alternatives and COMMITTING to achieving them. :param current_beliefs: WordModel instance, the world model, information about the world. :param current_desires: List of tuples, tasks that the agent would like to accomplish. :param current_intentions: List of tuples, tasks that the agent has COMMITTED to accomplish. :return: List of tuples, filtered intentions that the agent COMMITS to accomplish. """ for current_intention in current_intentions: if current_intention == self.goals[0] and current_beliefs.current_world_model.location["target_object"] \ == "container": current_intentions = "" # if goal(s) achieved, empty I return current_intentions
from monitoring import Monitoring from records import Records # name = input("Please Enter name: ") # weight= int(input("Please Enter your weight in kg: ")) # calories=int(input("Please Enter your burned calory in kcal: ")) M1 = Monitoring("yuxuan", "female", 22, 174, 55, 1778) M1.new_weight(55) M1.new_calory(1893) M1.new_weight(56.4) M1.new_calory(1993) M1.new_weight(57.4) M1.new_calory(1893) M1.new_weight(58.4) M1.new_calory(1893) M1.new_weight(58.4) M1.weight_calory_plot()
def readdata(self, gpio): m = Monitoring() m.run() m.read(self.ser, gpio) m.store()
class TCPClient: def __init__(self): self._user = User() self._command = Command() self._type_package = 0 self.__readConfig() def send(self): package = Package() package.type = self._type_package package.user = self._user package.command = self._command PACKAGE = package.getPackage() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((TCP_IP, TCP_PORT)) s.send(PACKAGE) data = s.recv(BUFFER_SIZE) s.close() package = Package() package.setPackage(data) if package.type == 0: pass if package.type == 1: message = str(package.data) #message = message.split('$$NEWLINE$$ $$NEWLINE$$') #message = '\n'.join(message) #message = message.replace('$$NEWLINE$$','',1) print message if package.type == 2: print "Status: {}".format(package.data) if package.type == 3: print "Data sending" def setCommand(self, id, command, variables=''): var = ' '.join(variables) self._type_package = 0 self._command.id = id self._command.name = command self._command.variables = var #print "Calling command: ID={}: {}({})".format(self.command.id, self.command.name, self.command.variables) def setTypePackage(self, type=0): self._type_package = type def sendFile(self, filename): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((TCP_IP, TCP_PORT)) package = Package(3) package.command.variables = ' '.join([filename, 'wb']) print "Starting sending file" with open(filename,'rb') as file: print 'Sending..' data = file.read(2048) package.command.name = 'send_file' package.data = data.encode() s.send(package.getPackage()) package.command.variables = '{} {}'.format(filename, 'a') def __readConfig(self): self._configfile = 'client.ini' self._config = ConfigParser.RawConfigParser() self._config.read(self._configfile) self._monitoring = Monitoring() self._user.name = self._config.get("server", 'username') try: try: self.__TCP_IP = self._config.get("server", 'tcp_ip') except ConfigParser.NoOptionError: self.__TCP_IP = TCP_IP try: self.__TCP_PORT = self._config.getint("server", 'tcp_port') except ConfigParser.NoOptionError: self.__TCP_PORT = TCP_PORT try: self.__BUFFER_SIZE = self._config.getint("server", 'buffer_size') except ConfigParser.NoOptionError: self.__BUFFER_SIZE = BUFFER_SIZE except ConfigParser.NoSectionError: self.__TCP_IP = TCP_IP self.__TCP_PORT = TCP_PORT self.__BUFFER_SIZE = BUFFER_SIZE def getServerParameters(self): return self.__TCP_IP, self.__TCP_PORT, self.__BUFFER_SIZE def setServerParameters(self, tcp_ip, tcp_port, buffer_size): self.__TCP_IP = tcp_ip self.__TCP_PORT = tcp_port self.__BUFFER_SIZE = buffer_size self._config.set("server", 'ip', self.__TCP_IP) self._config.set("server", 'port', self.__TCP_PORT) self._config.set("server", 'buffer_size', self.__BUFFER_SIZE) with open(self._configfile, 'wb') as configfile: self._config.write(configfile) print self._monitoring.Status() message = "Set socket: {}:{}".format(self.__TCP_IP, TCP_PORT) self._monitoring.sendMessage(message) print self._monitoring.Status() def setUser(self, username): self._user.name = username print "Set username: {}".format(username) self._config.set("server", 'username', self._user.name) with open(self._configfile, 'wb') as configfile: self._config.write(configfile) def getUser(self): return self._user.name
class BDIBehaviour(PeriodicBehaviour): async def on_start(self): self.terminate = False self.SUCCESS = False self.verbose = False # Initialization self.htn_planner = HierarchicalTaskNetworkPlanner() self.goal = [('transfer_target_object_to_container', 'arm', 'target_object', 'table', 'container')] self.intentions = self.goal # I := I0; Initial Intentions self.beliefs = WorldModel() # B := B0; Initial Beliefs self.monitoring = Monitoring() self.perception = Perception() self.coordination = Coordination() # Disable all 3 coordination switches for testing self.coordination.control.send_requests = True self.coordination.control.center_init = False self.coordination.control.detect_last_position = True self.what, self.why, self.how_well, self.what_else, self.why_failed = "", "", "", "", "" self.plans = [] self.start_time = datetime.datetime.now() async def run(self): # print(f"-- Sender Agent: PeriodicSenderBehaviour running at {datetime.datetime.now().time()}: {self.counter}") print("run tick: {}".format(self.beliefs.current_world_model.tick)) # msg = Message(to="madks2@temp3rr0r-pc") # Instantiate the message # msg.body = "Hello World: " + str(self.counter) # Set the message content # await self.send(msg) self.add_belief() self.add_desire() self.add_intention() print("-- Sender Agent: Message sent!") if self.beliefs.update_tick( ) > self.beliefs.current_world_model.max_ticks: self.done() self.kill() else: SUCCESS = True if self.intentions == "" else False self.plans = self.htn_planner.get_plans( self.beliefs.current_world_model, self.intentions) # π := plan(B, I); MEANS_END REASONING async def on_end(self): print("-- on_end") # stop agent from behaviour await self.agent.stop() # async def _step(self): # # the bdi stuff # pass # def add_belief(self): print("-- Sender Agent: add_belief") percept = self.perception.get_percept(text_engraving=( self.why_failed, self.how_well)) # get next percept ρ; OBSERVE the world self.beliefs = self.perception.belief_revision( self.beliefs, percept) # B:= brf(B, ρ); self.beliefs = self.monitoring.fire_events(self.beliefs, percept) def add_desire(self): print("-- Sender Agent: add_desire") def add_intention(self): print("-- Sender Agent: add_intention") self.intentions = self.deliberate( self.beliefs, self.intentions ) # DELIBERATE about what INTENTION to achieve next def done(self): # the done evaluation print("-- Sender Agent: Done") def deliberate(self, current_beliefs, current_intentions): """ Decide WHAT sate of affairs you want to achieve. :param current_beliefs: WordModel instance, the world model, information about the world. :param current_intentions: List of tuples, tasks that the agent has COMMITTED to accomplish. :return: List of tuples, filtered intentions that the agent COMMITS to accomplish. """ # 1. Option Generation: The agent generates a set of possible alternatives. current_desires = current_intentions # TODO: D := option(B, I); # 2. Filtering: Agent chooses between competing alternatives and commits to achieving them. current_intentions = self.filter_intentions( current_beliefs, current_desires, current_intentions) # I := filter(B, D, I); return current_intentions def filter_intentions(self, current_beliefs, current_desires, current_intentions): """ Choose between competing alternatives and COMMITTING to achieving them. :param current_beliefs: WordModel instance, the world model, information about the world. :param current_desires: List of tuples, tasks that the agent would like to accomplish. :param current_intentions: List of tuples, tasks that the agent has COMMITTED to accomplish. :return: List of tuples, filtered intentions that the agent COMMITS to accomplish. """ for current_intention in current_intentions: if current_intention == ( 'transfer_target_object_to_container', 'arm', 'target_object', 'table', 'container') \ and current_beliefs.current_world_model.location["target_object"] == "container": current_intentions = "" # if goal(s) achieved, empty I return current_intentions
class SimpleNetworkExperiment(Experiment): def __init__(self, conn, conf_file, setName, title, duration, tcpdump_if, tcpdump_port): self.conn = conn self.conf_file = conf_file self.setName = setName self.title = title self.duration = duration self.tcpdump_if = tcpdump_if self.tcpdump_port = tcpdump_port self.exp_name = 'exp_' + title + '_' + str(int(time.time())) self.mon_controller = self.conn.monHostName self.iot = self.conn.monHostName # this is the same host where the Lattice controller id running self.edge = self.conn.clusterMgmHostName # the host where the processing functions are (cm in the case of faas / containers) self.receiver = self.conn.receiverHostName Experiment.__init__(self, conn, self.exp_name, self.setName) self.init() def startIoT(self): command = 'java -cp /home/uceeftu/lattice/jars/monitoring-bin-core-2.0.1.jar mon.lattice.appl.demo.iot.IotEmulator ' \ + self.conf_file + ' ' + str(self.duration) result = self.monHost.run(command) def init(self): # create dir: /home/setName/name/ self.exp_path = os.getenv("HOME") + '/' + self.setName + '/' if not os.path.exists(self.exp_path): os.makedirs(self.exp_path) self.exp_path = self.exp_path + self.exp_name os.mkdir(self.exp_path) print('Starting experiment ' + self.setName + ' / ' + self.exp_name) print('Redirecting output to: ' + self.exp_path + '/output.log') print('Redirecting error to: ' + self.exp_path + '/error.log') self.stdout = sys.stdout self.stderr = sys.stderr sys.stdout = open(self.exp_path + '/output.log', 'w') sys.stderr = open(self.exp_path + '/error.log', 'w') #setting exp title in file f = open(self.exp_path + '/title.txt', 'w') f.write(self.title) f.close() print('+++ IoT: ' + self.conn.monHostName) print('+++ Edge: ' + self.conn.clusterMgmHostName) print('+++ Receiver: ' + self.conn.receiverHostName) def cleanup(self): sys.stdout.close() sys.stderr.close() sys.stdout = self.stdout sys.stderr = self.stderr print('Experiment ' + self.exp_path + ' completed') def startMon(self): print('Starting Mon') self.monitor = Monitoring(self.mon_controller, '6666', self.exp_path, self.iot, self.edge, self.tcpdump_if, self.tcpdump_port, self.receiver) self.monitor.init() self.monitor.set_consumer_pid(self.consumer_PID) self.monitor.start_components() self.monitor.start_monitoring() def stopMon(self): print('Stopping Mon') self.monitor.stop_monitoring() self.monitor.stop_components() self.monitor.cleanup() self.__cleanup_tcpdump() #we need this until we manage to kill child tcpdump process properly def __cleanup_tcpdump(self): command = 'killall tcpdump' result = self.clusterMgmHost.sudo(command, pty=True) def saveIotConf(self): # copy iot.properties into setName/name print('Saving iot emulator conf file') copy(self.conf_file, self.exp_path + '/iot.properties') def startConsumer(): raise NotImplementedError('subclasses must override startConsumer!') def stopConsumer(): raise NotImplementedError('subclasses must override stopConsumer!') def collectLatticeLogs(self): directory = self.exp_path + '/ds/' command = 'mkdir ' + directory result = self.monHost.run(command) if result.ok == True: command = 'cp /tmp/data-source-* ' + directory result = self.monHost.run(command) if result.ok == True: print('Successfully imported ds logs') Experiment.collectLatticeLogs(self) def collectConsumerStats(self): directory = self.exp_path + '/' command = 'mv /tmp/stats_*.log ' + directory result = self.clusterMgmHost.run(command) if result.ok == True: print('Successfully imported consumer stats') def start(self): self.startLattice() self.startConsumer() self.startMon() self.startIoT() self.stopMon() self.stopConsumer() self.stopLattice() self.collectLatticeLogs() self.saveIotConf() self.collectTimestamp() self.collectConsumerStats() self.cleanup()
c1 = CTControllerScaleXNode(1, initCores, maxCores, BC=3, DC=15) c2 = OPTCTRL(monitoringWindow, init_cores=initCores, st=0.8, stime=[1 / stimes[i] for i in range(appsCount)], maxCores=maxCores) c2.setName("OPTCTRL") c2.reset() runner = Runner( horizon, [c2, c1], monitoringWindow, app, lambda window, sla: MultiMonitoring( [Monitoring(monitoringWindow, appsSLA[i]) for i in range(appsCount)]), name=name) g = MultiGenerator([SP2, RP2]) runner.run(g) g = MultiGenerator([RP2, SP2]) runner.run(g) g = MultiGenerator([SN2, SP2]) runner.run(g) g = MultiGenerator([SP2, SN2]) runner.run(g) g = MultiGenerator([SN2, RP2]) runner.run(g)
class Gru: def __init__(self): self.minions = [] self.monitor = None def start_monitoring_local(self): # monitoring lokal in thread starten if self.monitor is None: self.monitor = Monitoring() self.monitor.start() return True else: return False def start_monitoring_remote(self, remote): # TODO Monitoring mithilfe von salt auf minion starten return False def stop_monitoring_local(self): if self.monitor is None: return False else: self.monitor.stop() self.monitor = None return True def stop_monitoring_remote(self, remote): requests.get("http://{}:5000/stop".format(remote)) def add_regex_local(self, regex): # einen neuen regelären ausdruck für den lokalen monitor hinzufügen if self.monitor is None: return False else: self.monitor.regs.append(regex) return True def add_regex_remote(self, remote, regex): # einen neuen regelären ausdruck für den remote monitor hinzufügen requests.post("http://{}:5000/add_regex".format(remote), data={'regex': regex}) def remove_regex_local(self, regex): if self.monitor is None: return False else: self.monitor.remove_regex(regex) return True def remove_regex_remote(self, remote, regex): requests.post("http://{}:5000/del_regex".format(remote), data={'regex': regex}) def list_regex_local(self): if self.monitor is None: return None else: return self.monitor.regs def list_regex_remote(self, remote): response = requests.get("http://{}:5000/list_regex".format(remote)) return json.loads(response.content) def get_events(self): events = [] if self.monitor is not None: events.extend(self.monitor.get_events_dict()) for minion in self.minions: response = requests.get("http://{}:5000/get_events".format(minion)) events.extend(json.loads(response.content)) # events von allen aktiven monitor instanzen abfragen return events
class DeepQNetwork(object): def __init__(self, height, width, num_actions, state_frames, gamma, batch_size=32): self.gamma = gamma self.num_actions = num_actions self.input_var = T.tensor4('inputs') self.target_var = T.vector('targets') self.actions_var = T.matrix() self.input_shared = theano.shared(np.zeros([batch_size, state_frames, height, width]), dtype=theano.tensor.floatX) self.taret_shared = theano.shared(np.zeros([batch_size, 1]), dtype=theano.tensor.floatX) self.actions_shared = theano.shared(np.zeros([batch_size, num_actions]).astype('int32'), dtype=theano.tensor.int32) self.net = get_inference(self.input_var, num_actions, height, width, state_frames) self.prediction = (lasagne.layers.get_output(self.net) * self.actions_var).sum(axis=1) self.error = T.sqr(self.target_var - self.prediction).mean() params = lasagne.layers.get_all_params(self.net, trainable=True) #self.opt = lasagne.updates.rmsprop( # self.error, params, learning_rate=0.0025, epsilon=0.01) #self.opt = lasagne.updates.adagrad( # self.error, params, learning_rate=0.001 #) self.opt = gen_updates_rmsprop(params, T.grad(self.error, params)) self.train_step = theano.function([self.input_var, self.target_var, self.actions_var], self.error, updates=self.opt, allow_input_downcast=True) self.net_fun = theano.function([self.input_var], lasagne.layers.get_output(self.net), allow_input_downcast=True) self.monitor = Monitoring() self.pred_fun = theano.function([self.input_var, self.actions_var], self.prediction, allow_input_downcast=True) self.error_fun = theano.function([self.input_var, self.target_var, self.actions_var], self.error, allow_input_downcast=True) def get_best_action(self, example): vals = self.evaluate_network([example])[0] return np.argmax(vals), vals def evaluate_network(self, batch): return self.net_fun(batch) def train(self, batch): batch_size = batch['batch_size'] self.monitor.report_action_start('get_target') target = self.get_target(batch) self.monitor.report_action_finish('get_target') actions = np.zeros([batch_size, self.num_actions]) actions[:, list(batch['actions'])] = 1 self.monitor.report_action_start('pred_fun') self.pred_fun(batch['states_1'], actions) self.monitor.report_action_finish('pred_fun') self.monitor.report_action_start('error_fun') self.error_fun(batch['states_1'], target, actions) self.monitor.report_action_finish('error_fun') self.monitor.report_action_start('train_step') error_val = self.train_step(batch['states_1'], target, actions) self.monitor.report_action_finish('train_step') return error_val def get_target(self, batch): batch_size = batch['batch_size'] self.monitor.report_action_start('only_q') q_vals = self.evaluate_network(batch['states_2']) self.monitor.report_action_finish('only_q') best_actions = np.argmax(q_vals, 1) target = np.choose(best_actions, q_vals.T) for i in xrange(batch_size): if batch['terminations'][i]: mul = 0 else: mul = self.gamma target[i] = batch['rewards'][i] + mul * target[i] return target
# flake8: noqa from flask import Flask, render_template from monitoring import Monitoring app = Flask(__name__) monitor = Monitoring(backend=False) @app.route('/') def main_page(): return "Your monitor is started" def run_webmonitor(): app.run() if __name__ == "__main__": run_webmonitor()
horizon = 300 monitoringWindow = 1 ctPeriod = 1 maxCores = 200000 Names=[f'App{i}' for i in range(1, appsCount+1)] srateAvg=[1.0/stime for stime in stimes] initCores=[1 for _ in stimes] app=AppsCluster(appNames=Names,srateAvg=srateAvg,initCores=initCores,isDeterministic=False) AppsCluster.sla=appsSLA c1 = CTControllerScaleXNode(1, initCores, maxCores, BCs=3, DCs=15) c2 = OPTCTRL(monitoringWindow, init_cores=initCores, st=0.8, stime=[1/stimes[i] for i in range(appsCount)],maxCores=maxCores) c2.setName("OPTCTRL") c2.reset() runner = Runner(horizon, [c2], monitoringWindow, app, lambda window, sla: MultiMonitoring([Monitoring(monitoringWindow, appsSLA[i]) for i in range(appsCount)]), name=name) g = MultiGenerator([RP1, RP1]) runner.run(g) # g = MultiGenerator([SN1, SN1]) # runner.run(g) # # g = MultiGenerator([SP1, SP1]) # runner.run(g) runner.log() runner.plot()
def main(): global monitor monitor = Monitoring() monitor.start() app.run(debug=True, use_reloader=False)