def run(self): """ Common collector cycle 1. Collect data 2. Sleep 3. Stop if object stopped """ # TODO: Standardize this with Managers. current_thread().name = self.short_name context.setup_thread_id() try: while True: context.inc_action_id() if self.object.running: self._collect() self._sleep() else: break raise GreenletExit # Since kill signals won't work, we raise it ourselves. except GreenletExit: context.log.debug( '%s collector for %s received exit signal' % (self.__class__.__name__, self.object.definition_hash)) except: context.log.error('%s collector run failed' % self.object.definition_hash, exc_info=True) raise
def run(self): """ Common collector cycle 1. Collect data 2. Sleep 3. Stop if object stopped """ # TODO: Standardize this with Managers. current_thread().name = self.short_name context.setup_thread_id() try: while True: context.inc_action_id() if self.object.running: self._collect() self._sleep() else: break raise GreenletExit # Since kill signals won't work, we raise it ourselves. except GreenletExit: context.log.debug( '%s collector for %s received exit signal' % (self.__class__.__name__, self.object.definition_hash) ) except: context.log.error( '%s collector run failed' % self.object.definition_hash, exc_info=True ) raise
def start(self): """ Execution entry point. Does some setup and then runs the _run routine. """ # TODO: Standardize this with collectors and managers. current_thread().name = self.name context.setup_thread_id() self.running = True context.inc_action_id() start = time.time() try: self._setup() self._run() except Exception as e: context.default_log.error( '"%s" critical exception "%s" caught during run' % (self.__class__.__name__, e.__class__.__name__)) context.default_log.debug('additional info:', exc_info=True) finally: try: self._teardown() finally: end = time.time() context.default_log.debug( '%s (%s) run complete in %0.2f' % (self.__class__.__name__, id(self), end - start)) self.stop()
def run(self): # get correct pid context.set_pid() # set thread name current_thread().name = 'supervisor' # get initial config from cloud self.talk_to_cloud(initial=True) # init object managers self.init_object_managers() if not self.object_managers: context.log.error('no object managers configured, stopping') return # run bridge manager self.bridge_object = Bridge() self.bridge = spawn(self.bridge_object.start) # main cycle while True: time.sleep(5.0) if not self.is_running: break try: context.inc_action_id() for object_manager_name in self.object_manager_order: object_manager = self.object_managers[object_manager_name] object_manager.run() try: if context.objects.root_object: if context.objects.root_object.definition and context.objects.root_object.definition_healthy: context.inc_action_id() self.talk_to_cloud(root_object=context.objects.root_object.definition) else: context.log.error('Problem with root object definition, agent stopping') self.stop() else: pass # context.default_log.debug('No root object defined during supervisor main run') except AmplifyCriticalException: pass self.check_bridge() except OSError as e: if e.errno == 12: # OSError errno 12 is a memory error (unable to allocate, out of memory, etc.) context.log.error('OSError: [Errno %s] %s' % (e.errno, e.message), exc_info=True) continue else: raise e
def run(self): # get correct pid context.set_pid() # set thread name current_thread().name = 'supervisor' # get initial config from cloud self.talk_to_cloud(initial=True) # init object managers self.init_object_managers() if not self.object_managers: context.log.error('no object managers configured, stopping') return # run bridge manager self.bridge_object = Bridge() self.bridge = spawn(self.bridge_object.start) # main cycle while True: time.sleep(5.0) if not self.is_running: break try: context.inc_action_id() for object_manager_name in self.object_manager_order: object_manager = self.object_managers[object_manager_name] object_manager.run() try: if context.objects.root_object: context.inc_action_id() self.talk_to_cloud( root_object=context.objects.root_object.definition) else: pass # context.default_log.debug('No root object defined during supervisor main run') except AmplifyCriticalException: pass self.check_bridge() except OSError as e: if e.errno == 12: # OSError errno 12 is a memory error (unable to allocate, out of memory, etc.) context.log.error('OSError: [Errno %s] %s' % (e.errno, e.message), exc_info=True) continue else: raise e
def start(self): current_thread().name = self.name context.setup_thread_id() self.running = True while self.running: self._wait(0.1) # This means that we don't increment every time a UDP message is handled, but rather every listen "period" context.inc_action_id() asyncore.loop(timeout=self.interval, count=10)
def start(self): """ Primary execution loop. Follows the pattern: wait, increment action id, call manager run method. """ # TODO: Standardize this with collectors. current_thread().name = self.name context.setup_thread_id() self.running = True while self.running: self._wait(self.interval) context.inc_action_id() self._run()
def start(self): """ Primary execution loop. Follows the pattern: wait, increment action id, call manager run method. """ # TODO: Standardize this with collectors. current_thread().name = self.name context.setup_thread_id() self.running = True try: while self.running: self._wait(self.interval) context.inc_action_id() self._run() except Exception as e: context.log.error('manager execution failed due to "%s"' % e.__class__.__name__) context.log.debug('additional info:', exc_info=True) raise e
def run(self): # get correct pid context.set_pid() # set thread name current_thread().name = 'supervisor' # get initial config from cloud self.talk_to_cloud(initial=True) # init object managers self.init_object_managers() # load ext managers self.load_ext_managers() if not self.object_managers: context.log.error('no object managers configured, stopping') return # run bridge manager self.bridge_object = Bridge() self.bridge = spawn(self.bridge_object.start) # register exit handlers atexit.register(self.stop_everything) atexit.register(self.bridge_object.flush_metrics) # main cycle while True: time.sleep(5.0) # stop if was running in debug mode for more than five minutes if self.debug_mode: elapsed_time = int(time.time()) - self.start_time if elapsed_time > self.debug_mode_time: self.stop() else: print "Agent is running in debug mode, %s seconds to go..." % ( self.debug_mode_time - elapsed_time) if not self.is_running: break try: context.inc_action_id() # run internal object managers for object_manager_name in self.object_manager_order: object_manager = self.object_managers[object_manager_name] object_manager.run() # run external object managers external_object_managers = filter( lambda x: x not in self.object_manager_order, self.object_managers.keys()) for object_manager_name in external_object_managers: object_manager = self.object_managers[object_manager_name] object_manager.run() # manage external regular managers self.manage_external_managers() # talk to cloud try: if context.objects.root_object: if context.objects.root_object.definition and context.objects.root_object.definition_healthy: context.inc_action_id() self.talk_to_cloud(root_object=context.objects. root_object.definition) else: context.log.error( 'Problem with root object definition, agent stopping' ) self.stop() else: pass # context.default_log.debug('No root object defined during supervisor main run') except AmplifyCriticalException: pass self.check_bridge() except OSError as e: if e.errno == 12: # OSError errno 12 is a memory error (unable to allocate, out of memory, etc.) context.log.error('OSError: [Errno %s] %s' % (e.errno, e.message), exc_info=True) continue else: raise e