def update(self, process_list): """Update the AMP""" # Get the systemctl status logger.debug('{}: Update stats using systemctl {}'.format( self.NAME, self.get('systemctl_cmd'))) try: res = check_output(self.get('systemctl_cmd').split()) except (OSError, CalledProcessError) as e: logger.debug('{}: Error while executing systemctl ({})'.format( self.NAME, e)) else: status = {} # For each line for r in to_ascii(res).split('\n')[1:-8]: # Split per space .* column = r.split() if len(column) > 3: # load column for c in range(1, 3): try: status[column[c]] += 1 except KeyError: status[column[c]] = 1 # Build the output (string) message output = 'Services\n' for k, v in iteritems(status): output += '{}: {}\n'.format(k, v) self.set_result(output, separator=' ') return self.result()
def update(self, process_list): """Update the AMP""" # Get the systemctl status logger.debug('{}: Update AMP stats using command {}'.format( self.NAME, self.get('service_cmd'))) # Get command to execute try: res = self.get('command') except OSError as e: logger.debug('{}: Error while executing command ({})'.format( self.NAME, e)) return self.result() # No command found, use default message if res is None: # Set the default message if command return None # Default sum of CPU and MEM for the matching regex self.set_result('CPU: {:.1f}% | MEM: {:.1f}%'.format( sum([p['cpu_percent'] for p in process_list]), sum([p['memory_percent'] for p in process_list]))) return self.result() # Run command(s) # Comman separated commands can be executed try: msg = '' for cmd in res.split(';'): msg += u(check_output(cmd.split(), stderr=STDOUT)) self.set_result(to_ascii(msg.rstrip())) except CalledProcessError as e: self.set_result(e.output) return self.result()
def update(self, process_list): """Update the AMP""" # Get the systemctl status logger.debug('{}: Update AMP stats using service {}'.format( self.NAME, self.get('service_cmd'))) try: res = self.get('command') except OSError as e: logger.debug('{}: Error while executing service ({})'.format( self.NAME, e)) else: if res is not None: try: msg = u(check_output(res.split(), stderr=STDOUT)) self.set_result(to_ascii(msg.rstrip())) except CalledProcessError as e: self.set_result(e.output) else: # Set the default message if command return None # Default sum of CPU and MEM for the matching regex self.set_result('CPU: {:.1f}% | MEM: {:.1f}%'.format( sum([p['cpu_percent'] for p in process_list]), sum([p['memory_percent'] for p in process_list]))) return self.result()
def update(self, process_list): """Update the AMP""" # Get the systemctl status logger.debug('{}: Update stats using systemctl {}'.format(self.NAME, self.get('systemctl_cmd'))) try: res = check_output(self.get('systemctl_cmd').split()) except (OSError, CalledProcessError) as e: logger.debug('{}: Error while executing systemctl ({})'.format(self.NAME, e)) else: status = {} # For each line for r in to_ascii(res).split('\n')[1:-8]: # Split per space .* column = r.split() if len(column) > 3: # load column for c in range(1, 3): try: status[column[c]] += 1 except KeyError: status[column[c]] = 1 # Build the output (string) message output = 'Services\n' for k, v in iteritems(status): output += '{}: {}\n'.format(k, v) self.set_result(output, separator=' ') return self.result()
def msg_curse(self, args=None): """Return the string to display in the curse interface.""" # Init the return message ret = [] if not self.stats or self.stats == {} or self.is_disable(): return ret # Generate the output if 'ami-id' in self.stats and 'region' in self.stats: msg = 'AWS EC2' ret.append(self.curse_add_line(msg, "TITLE")) msg = ' {} instance {} ({})'.format(to_ascii(self.stats['instance-type']), to_ascii(self.stats['instance-id']), to_ascii(self.stats['region'])) ret.append(self.curse_add_line(msg)) # Return the message with decoration logger.info(ret) return ret
def msg_curse(self, args=None): """Return the string to display in the curse interface.""" # Init the return message ret = [] if not self.stats or self.stats == {} or self.is_disable(): return ret # Generate the output if 'ami-id' in self.stats and 'region' in self.stats: msg = 'AWS EC2' ret.append(self.curse_add_line(msg, "TITLE")) msg = ' {} instance {} ({})'.format( to_ascii(self.stats['instance-type']), to_ascii(self.stats['instance-id']), to_ascii(self.stats['region'])) ret.append(self.curse_add_line(msg)) # Return the message with decoration logger.info(ret) return ret
def update(self, process_list): """Update the AMP""" # Get the systemctl status logger.debug('{}: Update stats using service {}'.format(self.NAME, self.get('service_cmd'))) try: res = self.get('command') except OSError as e: logger.debug('{}: Error while executing service ({})'.format(self.NAME, e)) else: if res is not None: msg = u(check_output(res.split(), stderr=STDOUT)) self.set_result(to_ascii(msg.rstrip())) else: # Set the default message if command return None # Default sum of CPU and MEM for the matching regex self.set_result('CPU: {:.1f}% | MEM: {:.1f}%'.format( sum([p['cpu_percent'] for p in process_list]), sum([p['memory_percent'] for p in process_list]))) return self.result()
def run(self): """Grab plugin's stats. Infinite loop, should be stopped by calling the stop() method """ if import_error_tag: self.stop() return False for k, v in iteritems(self.OPENSTACK_API_METADATA): r_url = '{}/{}'.format(self.OPENSTACK_API_URL, v) try: # Local request, a timeout of 3 seconds is OK r = requests.get(r_url, timeout=3) except Exception as e: logger.debug('cloud plugin - Cannot connect to the OpenStack metadata API {}: {}'.format(r_url, e)) break else: if r.ok: self._stats[k] = to_ascii(r.content) return True
def run(self): """Grab plugin's stats. Infinite loop, should be stopped by calling the stop() method """ if import_error_tag: self.stop() return False for k, v in iteritems(self.OPENSTACK_API_METADATA): r_url = '{}/{}'.format(self.OPENSTACK_API_URL, v) try: # Local request, a timeout of 3 seconds is OK r = requests.get(r_url, timeout=3) except Exception as e: logger.debug( 'cloud plugin - Cannot connect to the OpenStack metadata API {}: {}' .format(r_url, e)) break else: if r.ok: self._stats[k] = to_ascii(r.content) return True