Example #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 args.disable_process:
            msg = _("PROCESSES DISABLED (press 'z' to display)")
            ret.append(self.curse_add_line(msg))
            return ret

        if self.stats == {}:
            return ret

        # Display the filter (if it exists)
        if glances_processes.get_process_filter() is not None:
            msg = _("Processes filter:")
            ret.append(self.curse_add_line(msg, "TITLE"))
            msg = _(" {0} ").format(glances_processes.get_process_filter())
            ret.append(self.curse_add_line(msg, "FILTER"))
            msg = _("(press ENTER to edit)")
            ret.append(self.curse_add_line(msg))
            ret.append(self.curse_new_line())

        # 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
        if glances_processes.getmanualsortkey() is None:
            msg = _("sorted automatically")
            ret.append(self.curse_add_line(msg))
            msg = _(" by {0}").format(glances_processes.getautosortkey())
            ret.append(self.curse_add_line(msg))
        else:
            msg = _("sorted by {0}").format(
                glances_processes.getmanualsortkey())
            ret.append(self.curse_add_line(msg))

        # Return the message with decoration
        return ret
Example #2
0
    def display(self, stats, cs_status="None"):
        """Display stats on the screen.

        stats: Stats database to display
        cs_status:
            "None": standalone or server mode
            "Connected": Client is connected to a Glances server
            "SNMP": Client is connected to a SNMP server
            "Disconnected": Client is disconnected from the server

        Return:
            True if the stats have been displayed
            False if the help have been displayed
        """
        # Init the internal line/column for Glances Curses
        self.init_line_column()

        # Get the screen size
        screen_x = self.screen.getmaxyx()[1]
        screen_y = self.screen.getmaxyx()[0]

        # No processes list in SNMP mode
        if cs_status == 'SNMP':
            # so... more space for others plugins
            plugin_max_width = 43
        else:
            plugin_max_width = None

        # Update the stats messages
        ###########################

        # Update the client server status
        self.args.cs_status = cs_status
        stats_system = stats.get_plugin(
            'system').get_stats_display(args=self.args)
        stats_uptime = stats.get_plugin('uptime').get_stats_display()
        if self.args.percpu:
            stats_percpu = stats.get_plugin('percpu').get_stats_display()
        else:
            stats_cpu = stats.get_plugin('cpu').get_stats_display()
        stats_load = stats.get_plugin('load').get_stats_display()
        stats_mem = stats.get_plugin('mem').get_stats_display()
        stats_memswap = stats.get_plugin('memswap').get_stats_display()
        stats_network = stats.get_plugin('network').get_stats_display(
            args=self.args, max_width=plugin_max_width)
        stats_diskio = stats.get_plugin(
            'diskio').get_stats_display(args=self.args)
        stats_fs = stats.get_plugin('fs').get_stats_display(
            args=self.args, max_width=plugin_max_width)
        stats_sensors = stats.get_plugin(
            'sensors').get_stats_display(args=self.args)
        stats_now = stats.get_plugin('now').get_stats_display()
        stats_processcount = stats.get_plugin(
            'processcount').get_stats_display(args=self.args)
        stats_monitor = stats.get_plugin(
            'monitor').get_stats_display(args=self.args)
        stats_alert = stats.get_plugin(
            'alert').get_stats_display(args=self.args)

        # Adapt number of processes to the available space
        max_processes_displayed = screen_y - 11 - \
            self.get_stats_display_height(stats_alert)
        if self.args.enable_process_extended and not self.args.process_tree:
            max_processes_displayed -= 4
        if max_processes_displayed < 0:
            max_processes_displayed = 0
        if glances_processes.get_max_processes() is None or \
           glances_processes.get_max_processes() != max_processes_displayed:
            logger.debug("Set number of displayed processes to %s" %
                         max_processes_displayed)
            glances_processes.set_max_processes(max_processes_displayed)

        stats_processlist = stats.get_plugin(
            'processlist').get_stats_display(args=self.args)

        # Display the stats on the curses interface
        ###########################################

        # Help screen (on top of the other stats)
        if self.args.help_tag:
            # Display the stats...
            self.display_plugin(
                stats.get_plugin('help').get_stats_display(args=self.args))
            # ... and exit
            return False

        # Display first line (system+uptime)
        self.new_line()
        l = self.get_stats_display_width(
            stats_system) + self.get_stats_display_width(stats_uptime) + self.space_between_column
        self.display_plugin(stats_system, display_optional=(screen_x >= l))
        self.new_column()
        self.display_plugin(stats_uptime)

        # Display second line (CPU|PERCPU+LOAD+MEM+SWAP+<SUMMARY>)
        # CPU|PERCPU
        self.init_column()
        self.new_line()
        if self.args.percpu:
            l = self.get_stats_display_width(stats_percpu)
        else:
            l = self.get_stats_display_width(stats_cpu)
        l += self.get_stats_display_width(stats_load) + self.get_stats_display_width(
            stats_mem) + self.get_stats_display_width(stats_memswap)
        # Space between column
        space_number = int(stats_load['msgdict'] != [
        ]) + int(stats_mem['msgdict'] != []) + int(stats_memswap['msgdict'] != [])
        if space_number == 0:
            space_number = 1
        if screen_x > (space_number * self.space_between_column + l):
            self.space_between_column = int((screen_x - l) / space_number)
        # Display
        if self.args.percpu:
            self.display_plugin(stats_percpu)
        else:
            self.display_plugin(stats_cpu, display_optional=(screen_x >= 80))
        self.new_column()
        self.display_plugin(stats_load)
        self.new_column()
        self.display_plugin(stats_mem, display_optional=(
            screen_x >= (space_number * self.space_between_column + l)))
        self.new_column()
        self.display_plugin(stats_memswap)
        # Space between column
        self.space_between_column = 3

        # Backup line position
        self.saved_line = self.next_line

        # Display left sidebar (NETWORK+DISKIO+FS+SENSORS+Current time)
        self.init_column()
        if (not (self.args.disable_network and self.args.disable_diskio
                 and self.args.disable_fs and self.args.disable_sensors)) \
                and not self.args.disable_left_sidebar:
            self.new_line()
            self.display_plugin(stats_network)
            self.new_line()
            self.display_plugin(stats_diskio)
            self.new_line()
            self.display_plugin(stats_fs)
            self.new_line()
            self.display_plugin(stats_sensors)
            self.new_line()
            self.display_plugin(stats_now)

        # If space available...
        if screen_x > 52:
            # Restore line position
            self.next_line = self.saved_line

            # Display right sidebar
            # (PROCESS_COUNT+MONITORED+PROCESS_LIST+ALERT)
            self.new_column()
            self.new_line()
            self.display_plugin(stats_processcount)
            if glances_processes.get_process_filter() is None and cs_status == 'None':
                # Do not display stats monitor list if a filter exist
                self.new_line()
                self.display_plugin(stats_monitor)
            self.new_line()
            self.display_plugin(stats_processlist,
                                display_optional=(screen_x > 102),
                                display_additional=(not is_mac),
                                max_y=(screen_y - self.get_stats_display_height(stats_alert) - 2))
            self.new_line()
            self.display_plugin(stats_alert)

        # History option
        # Generate history graph
        if self.history_tag and self.args.enable_history:
            self.display_popup(
                _("Generate graphs history in %s\nPlease wait...") % self.glances_history.get_output_folder())
            self.display_popup(
                _("Generate graphs history in %s\nDone: %s graphs generated") % (self.glances_history.get_output_folder(), self.glances_history.generate_graph(stats)))
        elif self.reset_history_tag and self.args.enable_history:
            self.display_popup(_("Reset history"))
            self.glances_history.reset(stats)
        elif (self.history_tag or self.reset_history_tag) and not self.args.enable_history:
            try:
                self.glances_history.graph_enabled()
            except Exception:
                self.display_popup(
                    _("History disabled\nEnable it using --enable-history"))
            else:
                self.display_popup(
                    _("History disabled\nPlease install MatPlotLib"))
        self.history_tag = False
        self.reset_history_tag = False

        # Display edit filter popup
        # Only in standalone mode (cs_status == 'None')
        if self.edit_filter and cs_status == 'None':
            new_filter = self.display_popup(_("Process filter pattern: "),
                                            is_input=True,
                                            input_value=glances_processes.get_process_filter())
            glances_processes.set_process_filter(new_filter)
        elif self.edit_filter and cs_status != 'None':
            self.display_popup(
                _("Process filter only available in standalone mode"))
        self.edit_filter = False

        return True
Example #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 args.disable_process:
            msg = _("PROCESSES DISABLED (press 'z' to display)")
            ret.append(self.curse_add_line(msg))
            return ret

        if self.stats == {}:
            return ret

        # Display the filter (if it exists)
        if glances_processes.get_process_filter() is not None:
            msg = _("Processes filter:")
            ret.append(self.curse_add_line(msg, "TITLE"))
            msg = _(" {0} ").format(glances_processes.get_process_filter())
            ret.append(self.curse_add_line(msg, "FILTER"))
            msg = _("(press ENTER to edit)")
            ret.append(self.curse_add_line(msg))
            ret.append(self.curse_new_line())

        # 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
        if glances_processes.getmanualsortkey() is None:
            msg = _("sorted automatically")
            ret.append(self.curse_add_line(msg))
            msg = _(" by {0}").format(glances_processes.getautosortkey())
            ret.append(self.curse_add_line(msg))
        else:
            msg = _("sorted by {0}").format(glances_processes.getmanualsortkey())
            ret.append(self.curse_add_line(msg))

        # Return the message with decoration
        return ret
Example #4
0
    def display(self, stats, cs_status="None"):
        """Display stats on the screen.

        stats: Stats database to display
        cs_status:
            "None": standalone or server mode
            "Connected": Client is connected to a Glances server
            "SNMP": Client is connected to a SNMP server
            "Disconnected": Client is disconnected from the server

        Return:
            True if the stats have been displayed
            False if the help have been displayed
        """
        # Init the internal line/column for Glances Curses
        self.init_line_column()

        # Get the screen size
        screen_x = self.screen.getmaxyx()[1]
        screen_y = self.screen.getmaxyx()[0]

        # No processes list in SNMP mode
        if cs_status == 'SNMP':
            # so... more space for others plugins
            plugin_max_width = 43
        else:
            plugin_max_width = None

        # Update the stats messages
        ###########################

        # Update the client server status
        self.args.cs_status = cs_status
        stats_system = stats.get_plugin('system').get_stats_display(
            args=self.args)
        stats_uptime = stats.get_plugin('uptime').get_stats_display()
        if self.args.percpu:
            stats_percpu = stats.get_plugin('percpu').get_stats_display()
        else:
            stats_cpu = stats.get_plugin('cpu').get_stats_display()
        stats_load = stats.get_plugin('load').get_stats_display()
        stats_mem = stats.get_plugin('mem').get_stats_display()
        stats_memswap = stats.get_plugin('memswap').get_stats_display()
        stats_network = stats.get_plugin('network').get_stats_display(
            args=self.args, max_width=plugin_max_width)
        stats_diskio = stats.get_plugin('diskio').get_stats_display(
            args=self.args)
        stats_fs = stats.get_plugin('fs').get_stats_display(
            args=self.args, max_width=plugin_max_width)
        stats_sensors = stats.get_plugin('sensors').get_stats_display(
            args=self.args)
        stats_now = stats.get_plugin('now').get_stats_display()
        stats_processcount = stats.get_plugin(
            'processcount').get_stats_display(args=self.args)
        stats_monitor = stats.get_plugin('monitor').get_stats_display(
            args=self.args)
        stats_alert = stats.get_plugin('alert').get_stats_display(
            args=self.args)

        # Adapt number of processes to the available space
        max_processes_displayed = screen_y - 11 - self.get_stats_display_height(
            stats_alert)
        if not self.args.disable_process_extended:
            max_processes_displayed -= 4
        if max_processes_displayed < 0:
            max_processes_displayed = 0
        if glances_processes.get_max_processes() is None or \
           glances_processes.get_max_processes() != max_processes_displayed:
            logger.debug(
                _("Set number of displayed processes to %s") %
                max_processes_displayed)
            glances_processes.set_max_processes(max_processes_displayed)

        stats_processlist = stats.get_plugin('processlist').get_stats_display(
            args=self.args)

        # Display the stats on the curses interface
        ###########################################

        # Help screen (on top of the other stats)
        if self.args.help_tag:
            # Display the stats...
            self.display_plugin(
                stats.get_plugin('help').get_stats_display(args=self.args))
            # ... and exit
            return False

        # Display first line (system+uptime)
        self.new_line()
        l = self.get_stats_display_width(
            stats_system) + self.get_stats_display_width(
                stats_uptime) + self.space_between_column
        self.display_plugin(stats_system, display_optional=(screen_x >= l))
        self.new_column()
        self.display_plugin(stats_uptime)

        # Display second line (CPU|PERCPU+LOAD+MEM+SWAP+<SUMMARY>)
        # CPU|PERCPU
        self.init_column()
        self.new_line()
        if self.args.percpu:
            l = self.get_stats_display_width(stats_percpu)
        else:
            l = self.get_stats_display_width(stats_cpu)
        l += self.get_stats_display_width(
            stats_load) + self.get_stats_display_width(
                stats_mem) + self.get_stats_display_width(stats_memswap)
        # Space between column
        space_number = int(stats_load['msgdict'] != []) + int(
            stats_mem['msgdict'] != []) + int(stats_memswap['msgdict'] != [])
        if space_number == 0:
            space_number = 1
        if screen_x > (space_number * self.space_between_column + l):
            self.space_between_column = int((screen_x - l) / space_number)
        # Display
        if self.args.percpu:
            self.display_plugin(stats_percpu)
        else:
            self.display_plugin(stats_cpu, display_optional=(screen_x >= 80))
        self.new_column()
        self.display_plugin(stats_load)
        self.new_column()
        self.display_plugin(
            stats_mem,
            display_optional=(screen_x >=
                              (space_number * self.space_between_column + l)))
        self.new_column()
        self.display_plugin(stats_memswap)
        # Space between column
        self.space_between_column = 3

        # Backup line position
        self.saved_line = self.next_line

        # Display left sidebar (NETWORK+DISKIO+FS+SENSORS+Current time)
        self.init_column()
        self.new_line()
        self.display_plugin(stats_network)
        self.new_line()
        self.display_plugin(stats_diskio)
        self.new_line()
        self.display_plugin(stats_fs)
        self.new_line()
        self.display_plugin(stats_sensors)
        self.new_line()
        self.display_plugin(stats_now)

        # If space available...
        if screen_x > 52:
            # Restore line position
            self.next_line = self.saved_line

            # Display right sidebar (PROCESS_COUNT+MONITORED+PROCESS_LIST+ALERT)
            self.new_column()
            self.new_line()
            self.display_plugin(stats_processcount)
            if glances_processes.get_process_filter(
            ) == None and cs_status == 'None':
                # Do not display stats monitor list if a filter exist
                self.new_line()
                self.display_plugin(stats_monitor)
            self.new_line()
            self.display_plugin(
                stats_processlist,
                display_optional=(screen_x > 102),
                display_additional=(is_mac == False),
                max_y=(screen_y - self.get_stats_display_height(stats_alert) -
                       2))
            self.new_line()
            self.display_plugin(stats_alert)

        # History option
        # Generate history graph
        if self.history_tag and self.args.enable_history:
            self.display_popup(
                _("Graphs history generated in %s") %
                self.glances_history.get_output_folder())
            self.glances_history.generate_graph(stats)
        elif self.reset_history_tag and self.args.enable_history:
            self.display_popup(_("Reset history"))
            self.glances_history.reset(stats)
        elif (self.history_tag
              or self.reset_history_tag) and not self.args.enable_history:
            self.display_popup(
                _("History disabled\nEnable it using --enable-history"))
        self.history_tag = False
        self.reset_history_tag = False

        # Display edit filter popup
        # Only in standalone mode (cs_status == 'None')
        if self.edit_filter and cs_status == 'None':
            new_filter = self.display_popup(
                _("Process filter pattern: "),
                is_input=True,
                input_value=glances_processes.get_process_filter())
            glances_processes.set_process_filter(new_filter)
        elif self.edit_filter and cs_status != 'None':
            self.display_popup(
                _("Process filter only available in standalone mode"))
        self.edit_filter = False

        return True