Esempio n. 1
0
    def msg_curse(self, args=None):
        """Return the dict to display in the curse interface."""
        # Init the return message
        ret = []

        # Only process if stats exist and display plugin enable...
        # if self.stats == {} or args.disable_process:
        #     return ret

        if args.disable_process:
            msg = _("PROCESSES DISABLED (press 'z' to display)")
            ret.append(self.curse_add_line(msg))
            return ret

        if self.stats == {}:
            return ret

        # Build the string message
        # Header
        msg = _("TASKS ")
        ret.append(self.curse_add_line(msg, "TITLE"))
        # Compute processes
        other = self.stats['total']
        msg = str(self.stats['total'])
        ret.append(self.curse_add_line(msg))

        if 'thread' in self.stats:
            msg = _(" ({0} thr),").format(self.stats['thread'])
            ret.append(self.curse_add_line(msg))

        if 'running' in self.stats:
            other -= self.stats['running']
            msg = _(" {0} run,").format(self.stats['running'])
            ret.append(self.curse_add_line(msg))

        if 'sleeping' in self.stats:
            other -= self.stats['sleeping']
            msg = _(" {0} slp,").format(self.stats['sleeping'])
            ret.append(self.curse_add_line(msg))

        msg = _(" {0} oth ").format(other)
        ret.append(self.curse_add_line(msg))

        # Display sort information
        try:
            args.process_sorted_by
        except AttributeError:
            args.process_sorted_by = glances_processes.getsortkey()
        if args.process_sorted_by == 'auto':
            msg = _("sorted automatically")
            ret.append(self.curse_add_line(msg))
            msg = _(" by {0}").format(glances_processes.getsortkey())
            ret.append(self.curse_add_line(msg))
        else:
            msg = _("sorted by {0}").format(args.process_sorted_by)
            ret.append(self.curse_add_line(msg))

        # Return the message with decoration
        return ret
    def msg_curse(self, args=None):
        """Return the dict to display in the curse interface."""
        # Init the return message
        ret = []

        # Only process if stats exist and display plugin enable...
        if not self.stats or args.disable_process:
            return ret

        # Compute the sort key
        process_sort_key = glances_processes.getsortkey()
        sort_style = 'SORT'

        # Header
        msg = '{0:>6}'.format(_("CPU%"))
        ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'cpu_percent' else 'DEFAULT'))
        msg = '{0:>6}'.format(_("MEM%"))
        ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'memory_percent' else 'DEFAULT'))
        msg = '{0:>6}'.format(_("VIRT"))
        ret.append(self.curse_add_line(msg, optional=True))
        msg = '{0:>6}'.format(_("RES"))
        ret.append(self.curse_add_line(msg, optional=True))
        msg = '{0:>6}'.format(_("PID"))
        ret.append(self.curse_add_line(msg))
        msg = ' {0:10}'.format(_("USER"))
        ret.append(self.curse_add_line(msg))
        msg = '{0:>4}'.format(_("NI"))
        ret.append(self.curse_add_line(msg))
        msg = '{0:>2}'.format(_("S"))
        ret.append(self.curse_add_line(msg))
        msg = '{0:>9}'.format(_("TIME+"))
        ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'cpu_times' else 'DEFAULT', optional=True))
        msg = '{0:>6}'.format(_("IOR/s"))
        ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'io_counters' else 'DEFAULT', optional=True, additional=True))
        msg = '{0:>6}'.format(_("IOW/s"))
        ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'io_counters' else 'DEFAULT', optional=True, additional=True))
        msg = ' {0:8}'.format(_("Command"))
        ret.append(self.curse_add_line(msg))

        # Trying to display proc time
        self.tag_proc_time = True

        if glances_processes.is_tree_enabled():
            ret.extend(self.get_process_tree_curses_data(self.sortstats(process_sort_key),
                                                         args,
                                                         first_level=True,
                                                         max_node_count=glances_processes.get_max_processes()))
        else:
            # Loop over processes (sorted by the sort key previously compute)
            first = True
            for p in self.sortstats(process_sort_key):
                ret.extend(self.get_process_curses_data(p, first, args))
                # End of extended stats
                first = False

        # Return the message with decoration
        return ret
Esempio n. 3
0
    def msg_curse(self, args=None):
        """Return the dict to display in the curse interface."""
        # Init the return message
        ret = []

        # Only process if stats exist and display plugin enable...
        if self.stats == [] or args.disable_process:
            return ret

        # Compute the sort key
        try:
            args.process_sorted_by
        except AttributeError:
            args.process_sorted_by = glances_processes.getsortkey()
        if args.process_sorted_by == 'auto':
            process_sort_key = glances_processes.getsortkey()
        else:
            process_sort_key = args.process_sorted_by
        sort_style = 'SORT'

        # Header
        msg = '{0:>6}'.format(_("CPU%"))
        ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'cpu_percent' else 'DEFAULT'))
        msg = '{0:>6}'.format(_("MEM%"))
        ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'memory_percent' else 'DEFAULT'))
        msg = '{0:>6}'.format(_("VIRT"))
        ret.append(self.curse_add_line(msg, optional=True))
        msg = '{0:>6}'.format(_("RES"))
        ret.append(self.curse_add_line(msg, optional=True))
        msg = '{0:>6}'.format(_("PID"))
        ret.append(self.curse_add_line(msg))
        msg = ' {0:10}'.format(_("USER"))
        ret.append(self.curse_add_line(msg))
        msg = '{0:>4}'.format(_("NI"))
        ret.append(self.curse_add_line(msg))
        msg = '{0:>2}'.format(_("S"))
        ret.append(self.curse_add_line(msg))
        msg = '{0:>9}'.format(_("TIME+"))
        ret.append(self.curse_add_line(msg, optional=True))
        msg = '{0:>6}'.format(_("IOR/s"))
        ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'io_counters' else 'DEFAULT', optional=True))
        msg = '{0:>6}'.format(_("IOW/s"))
        ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'io_counters' else 'DEFAULT', optional=True))
        msg = ' {0:8}'.format(_("Command"))
        ret.append(self.curse_add_line(msg))

        # Trying to display proc time
        tag_proc_time = True

        # Loop over processes (sorted by the sort key previously compute)
        for p in self.sortlist(process_sort_key):
            ret.append(self.curse_new_line())
            # CPU
            msg = '{0:>6.1f}'.format(p['cpu_percent'])
            ret.append(self.curse_add_line(msg,
                                           self.get_alert(p['cpu_percent'], header="cpu")))
            # MEM
            msg = '{0:>6.1f}'.format(p['memory_percent'])
            ret.append(self.curse_add_line(msg,
                                           self.get_alert(p['memory_percent'], header="mem")))
            # VMS
            msg = '{0:>6}'.format(self.auto_unit(p['memory_info'][1], low_precision=False))
            ret.append(self.curse_add_line(msg, optional=True))
            # RSS
            msg = '{0:>6}'.format(self.auto_unit(p['memory_info'][0], low_precision=False))
            ret.append(self.curse_add_line(msg, optional=True))
            # PID
            msg = '{0:>6}'.format(p['pid'])
            ret.append(self.curse_add_line(msg))
            # USER
            # docker internal users are displayed as ints only, therefore str()
            msg = ' {0:9}'.format(str(p['username'])[:9])
            ret.append(self.curse_add_line(msg))
            # NICE
            nice = p['nice']
            if nice is None:
                nice = '?'
            msg = '{0:>5}'.format(nice)
            if nice != 0:
                ret.append(self.curse_add_line(msg, decoration='NICE'))
            else:
                ret.append(self.curse_add_line(msg))
            # STATUS
            status = p['status']
            msg = '{0:>2}'.format(status)
            if status == 'R':
                ret.append(self.curse_add_line(msg, decoration='STATUS'))
            else:
                ret.append(self.curse_add_line(msg))
            # TIME+
            if tag_proc_time:
                try:
                    dtime = timedelta(seconds=sum(p['cpu_times']))
                except Exception:
                    # Catched on some Amazon EC2 server
                    # See https://github.com/nicolargo/glances/issues/87
                    tag_proc_time = False
                else:
                    msg = '{0}:{1}.{2}'.format(str(dtime.seconds // 60 % 60),
                                               str(dtime.seconds % 60).zfill(2),
                                               str(dtime.microseconds)[:2].zfill(2))
            else:
                msg = ' '
            msg = '{0:>9}'.format(msg)
            ret.append(self.curse_add_line(msg, optional=True))
            # IO read/write
            if 'io_counters' in p:
                # IO read
                io_rs = (p['io_counters'][0] - p['io_counters'][2]) / p['time_since_update']
                if io_rs == 0:
                    msg = '{0:>6}'.format("0")
                else:
                    msg = '{0:>6}'.format(self.auto_unit(io_rs, low_precision=False))
                ret.append(self.curse_add_line(msg, optional=True))
                # IO write
                io_ws = (p['io_counters'][1] - p['io_counters'][3]) / p['time_since_update']
                if io_ws == 0:
                    msg = '{0:>6}'.format("0")
                else:
                    msg = '{0:>6}'.format(self.auto_unit(io_ws, low_precision=False))
                ret.append(self.curse_add_line(msg, optional=True))
            else:
                msg = '{0:>6}'.format("?")
                ret.append(self.curse_add_line(msg, optional=True))
                ret.append(self.curse_add_line(msg, optional=True))
            # Command line
            # If no command line for the process is available, fallback to
            # the bare process name instead
            cmdline = p['cmdline']
            if cmdline == "":
                msg = ' {0}'.format(p['name'])
                ret.append(self.curse_add_line(msg, splittable=True))
            else:
                try:
                    cmd = cmdline.split()[0]
                    args = ' '.join(cmdline.split()[1:])
                    path, basename = os.path.split(cmd)
                    if os.path.isdir(path):
                        msg = ' {0}'.format(path) + os.sep
                        ret.append(self.curse_add_line(msg, splittable=True))
                        ret.append(self.curse_add_line(basename, decoration='PROCESS', splittable=True))
                    else:
                        msg = ' {0}'.format(basename)
                        ret.append(self.curse_add_line(msg, decoration='PROCESS', splittable=True))
                    msg = " {0}".format(args)
                    ret.append(self.curse_add_line(msg, splittable=True))
                except UnicodeEncodeError:
                    ret.append(self.curse_add_line("", splittable=True))

        # Return the message with decoration
        return ret