Esempio n. 1
0
    def update(self):
        """Update the command result attributed."""
        # Only continue if monitor list is not empty
        if len(self.__monitor_list) == 0:
            return self.__monitor_list

        # Iter upon the monitored list
        for i in range(0, len(self.get())):
            # Search monitored processes by a regular expression
            processlist = glances_processes.getlist()
            monitoredlist = [p for p in processlist if re.search(self.regex(i), p['cmdline']) is not None]
            self.__monitor_list[i]['count'] = len(monitoredlist)

            if self.command(i) is None:
                # If there is no command specified in the conf file
                # then display CPU and MEM %
                self.__monitor_list[i]['result'] = 'CPU: {0:.1f}% | MEM: {1:.1f}%'.format(
                    sum([p['cpu_percent'] for p in monitoredlist]),
                    sum([p['memory_percent'] for p in monitoredlist]))
                continue
            else:
                # Execute the user command line
                try:
                    self.__monitor_list[i]['result'] = subprocess.check_output(self.command(i),
                                                                               shell=True)
                except subprocess.CalledProcessError:
                    self.__monitor_list[i]['result'] = _("Error: ") + self.command(i)
                except Exception:
                    self.__monitor_list[i]['result'] = _("Cannot execute command")

        return self.__monitor_list
Esempio n. 2
0
    def update(self):
        """Update the command result attributed."""
        # Only continue if monitor list is not empty
        if len(self.__monitor_list) == 0:
            return self.__monitor_list

        # Iter upon the monitored list
        for i in range(0, len(self.get())):
            # Search monitored processes by a regular expression
            processlist = glances_processes.getlist()
            monitoredlist = [p for p in processlist if re.search(self.regex(i), p['cmdline']) is not None]
            self.__monitor_list[i]['count'] = len(monitoredlist)

            if self.command(i) is None:
                # If there is no command specified in the conf file
                # then display CPU and MEM %
                self.__monitor_list[i]['result'] = 'CPU: {0:.1f}% | MEM: {1:.1f}%'.format(
                    sum([p['cpu_percent'] for p in monitoredlist]),
                    sum([p['memory_percent'] for p in monitoredlist]))
                continue
            else:
                # Execute the user command line
                try:
                    self.__monitor_list[i]['result'] = subprocess.check_output(self.command(i),
                                                                               shell=True)
                except subprocess.CalledProcessError:
                    self.__monitor_list[i]['result'] = _("Error: ") + self.command(i)
                except Exception:
                    self.__monitor_list[i]['result'] = _("Cannot execute command")

        return self.__monitor_list
Esempio n. 3
0
    def update(self):
        """Update processes stats using the input method."""
        # Reset stats
        self.reset()

        if self.get_input() == 'local':
            # Update stats using the standard system lib
            # Note: Update is done in the processcount plugin
            # Just return the processes list
            self.stats = glances_processes.getlist()
        elif self.get_input() == 'snmp':
            # No SNMP grab for processes
            pass

        return self.stats
Esempio n. 4
0
    def update(self):
        """Update processes stats using the input method."""
        # Reset stats
        self.reset()

        if self.get_input() == 'local':
            # Update stats using the standard system lib
            # Note: Update is done in the processcount plugin
            # Just return the processes list
            self.stats = glances_processes.getlist()            
        elif self.get_input() == 'snmp':
            # No SNMP grab for processes
            pass

        return self.stats