Beispiel #1
0
    def update(self):
        """Update the command result attributed."""
        # Search application monitored processes by a regular expression
        processlist = glances_processes.getalllist()
        # Iter upon the AMPs dict
        for k, v in iteritems(self.get()):
            if not v.enable():
                # Do not update if the enable tag is set
                continue
            try:
                amps_list = [p for p in processlist for c in p['cmdline'] if re.search(v.regex(), c) is not None]
            except TypeError:
                continue
            if len(amps_list) > 0:
                # At least one process is matching the regex
                logger.debug("AMPS: {} process detected (PID={})".format(k, amps_list[0]['pid']))
                # Call the AMP update method
                thread = threading.Thread(target=v.update_wrapper, args=[amps_list])
                thread.start()
            else:
                # Set the process number to 0
                v.set_count(0)
                if v.count_min() is not None and v.count_min() > 0:
                    # Only display the "No running process message" is countmin is defined
                    v.set_result("No running process")

        return self.__amps_dict
Beispiel #2
0
    def add(self,
            item_state,
            item_type,
            item_value,
            proc_list=None,
            proc_desc="",
            peak_time=6):
        """Add a new item to the logs list.

        If 'item' is a 'new one', add the new item at the beginning of
        the logs list.
        If 'item' is not a 'new one', update the existing item.
        If event < peak_time the the alert is not setoff.
        """
        proc_list = proc_list or glances_processes.getalllist()

        # Add or update the log
        item_index = self.__itemexist__(item_type)
        if item_index < 0:
            # Item did not exist, add if WARNING or CRITICAL
            self._create_item(item_state, item_type, item_value, proc_list,
                              proc_desc, peak_time)
        else:
            # Item exist, update
            self._update_item(item_index, item_state, item_type, item_value,
                              proc_list, proc_desc, peak_time)

        return self.len()
Beispiel #3
0
    def update(self):
        """Update the command result attributed."""
        # Search application monitored processes by a regular expression
        processlist = glances_processes.getalllist()
        # Iter upon the AMPs dict
        for k, v in iteritems(self.get()):
            if not v.enable():
                # Do not update if the enable tag is set
                continue
            try:
                amps_list = [
                    p for p in processlist for c in p['cmdline']
                    if re.search(v.regex(), c) is not None
                ]
            except TypeError:
                continue
            if len(amps_list) > 0:
                # At least one process is matching the regex
                logger.debug("AMPS: {} process detected (PID={})".format(
                    k, amps_list[0]['pid']))
                # Call the AMP update method
                thread = threading.Thread(target=v.update_wrapper,
                                          args=[amps_list])
                thread.start()
            else:
                # Set the process number to 0
                v.set_count(0)
                if v.count_min() is not None and v.count_min() > 0:
                    # Only display the "No running process message" is countmin is defined
                    v.set_result("No running process")

        return self.__amps_dict
Beispiel #4
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

        # Search monitored processes by a regular expression
        processlist = [p for p in glances_processes.getalllist()]

        # Iter upon the monitored list
        for i in range(len(self.get())):
            monitoredlist = [
                p for p in processlist for c in p['cmdline']
                if re.search(self.regex(i), c) is not None
            ]
            self.__monitor_list[i]['count'] = len(monitoredlist)

            # Always get processes CPU and MEM
            self.__monitor_list[i][
                'default_result'] = 'CPU: {0:.1f}% | MEM: {1:.1f}%'.format(
                    sum([p['cpu_percent'] for p in monitoredlist]),
                    sum([p['memory_percent'] for p in monitoredlist]))

            if self.command(i) is not None:
                # 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'

                # Only save the first line
                try:
                    self.__monitor_list[i]['result'] = u(
                        self.__monitor_list[i]['result']).split('\n')[0]
                except:
                    self.__monitor_list[i]['result'] = ''

            if self.command(
                    i) is None or self.__monitor_list[i]['result'] == '':
                # If there is no command specified in the conf file
                # then display CPU and MEM %
                self.__monitor_list[i]['result'] = self.__monitor_list[i][
                    'default_result']

        return self.__monitor_list
Beispiel #5
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

        # Search monitored processes by a regular expression
        processlist = [p for p in glances_processes.getalllist()]

        # Iter upon the monitored list
        for i in range(len(self.get())):
            monitoredlist = [p for p in processlist for c in p["cmdline"] if re.search(self.regex(i), c) is not None]
            self.__monitor_list[i]["count"] = len(monitoredlist)

            # Always get processes CPU and MEM
            self.__monitor_list[i]["default_result"] = "CPU: {0:.1f}% | MEM: {1:.1f}%".format(
                sum([p["cpu_percent"] for p in monitoredlist]), sum([p["memory_percent"] for p in monitoredlist])
            )

            if self.command(i) is not None:
                # 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"

                # Only save the first line
                try:
                    self.__monitor_list[i]["result"] = u(self.__monitor_list[i]["result"]).split("\n")[0]
                except:
                    self.__monitor_list[i]["result"] = ""

            if self.command(i) is None or self.__monitor_list[i]["result"] == "":
                # If there is no command specified in the conf file
                # then display CPU and MEM %
                self.__monitor_list[i]["result"] = self.__monitor_list[i]["default_result"]

        return self.__monitor_list
Beispiel #6
0
    def add(self, item_state, item_type, item_value,
            proc_list=None, proc_desc="", peak_time=6):
        """Add a new item to the logs list.

        If 'item' is a 'new one', add the new item at the beginning of
        the logs list.
        If 'item' is not a 'new one', update the existing item.
        If event < peak_time the the alert is not setoff.
        """
        proc_list = proc_list or glances_processes.getalllist()

        # Add or update the log
        item_index = self.__itemexist__(item_type)
        if item_index < 0:
            # Item did not exist, add if WARNING or CRITICAL
            self._create_item(item_state, item_type, item_value,
                              proc_list, proc_desc, peak_time)
        else:
            # Item exist, update
            self._update_item(item_index, item_state, item_type, item_value,
                              proc_list, proc_desc, peak_time)

        return self.len()