def Progress(self): """Indicate progress of the client action. This function should be called periodically during client actions that do not finish instantly. It will notify the nanny that the action is not stuck and avoid the timeout and it will also check if the action has reached its cpu limit. Raises: CPUExceededError: CPU limit exceeded. """ # Prevent the machine from sleeping while the action is running. client_utils.KeepAlive() if self.nanny_controller is None: self.nanny_controller = client_utils.NannyController() self.nanny_controller.Heartbeat() try: user_start, system_start = self.cpu_start user_end, system_end = self.proc.get_cpu_times() used_cpu = user_end - user_start + system_end - system_start if used_cpu > self.cpu_limit: self.grr_worker.SendClientAlert("Cpu limit exceeded.") raise CPUExceededError("Action exceeded cpu limit.") except AttributeError: pass
def __init__(self): """Create a new GRRClientWorker.""" super(GRRClientWorker, self).__init__() # Queue of messages from the server to be processed. self._in_queue = [] # Queue of messages to be sent to the server. self._out_queue = [] # A tally of the total byte count of messages self._out_queue_size = 0 self._is_active = False # Last time when we've sent stats back to the server. self.last_stats_sent_time = 0 self.proc = psutil.Process(os.getpid()) # Use this to control the nanny transaction log. self.nanny_controller = client_utils.NannyController() self.nanny_controller.StartNanny() if not GRRClientWorker.stats_collector: GRRClientWorker.stats_collector = client_stats.ClientStatsCollector( self) GRRClientWorker.stats_collector.start() self.lock = threading.RLock()
def __init__(self, sender_queue): """Constructor. Args: sender_queue: Queue.Queue """ self._sender_queue = sender_queue self.nanny_controller = client_utils.NannyController()
def SyncTransactionLog(self): """This flushes the transaction log. This function should be called by the client before performing potential dangerous actions so the server can get notified in case the whole machine crashes. """ if self.nanny_controller is None: self.nanny_controller = client_utils.NannyController() self.nanny_controller.SyncTransactionLog()
def __init__(self): """Create a new GRRClientWorker.""" super(GRRClientWorker, self).__init__() # Queue of messages from the server to be processed. self._in_queue = [] # Queue of messages to be sent to the server. self._out_queue = [] # A tally of the total byte count of messages self._out_queue_size = 0 self._is_active = False # If True, ClientStats will be forcibly sent to server during next # CheckStats() call, if less than STATS_MIN_SEND_INTERVAL time has passed # since last stats notification was sent. self._send_stats_on_check = False # Last time when we've sent stats back to the server. self.last_stats_sent_time = None self.proc = psutil.Process(os.getpid()) # We store suspended actions in this dict. We can retrieve the suspended # client action from here if needed. self.suspended_actions = {} # Use this to control the nanny transaction log. self.nanny_controller = client_utils.NannyController() self.nanny_controller.StartNanny() if not GRRClientWorker.stats_collector: GRRClientWorker.stats_collector = client_stats.ClientStatsCollector( self) GRRClientWorker.stats_collector.start() self.lock = threading.RLock()
def StartNanny(self): # Deliberatley no call to StartNanny() self.nanny_controller = client_utils.NannyController()