コード例 #1
0
    def __init__(self, config=None, args=None):
        # Init stats
        self.stats = GlancesStats(config=config, args=args)

        # Default number of processes to displayed is set to 20
        glances_processes.set_max_processes(20)

        # If process extended stats is disabled by user
        if args.disable_process_extended:
            logger.info(_("Extended stats for top process is disabled"))
            glances_processes.disable_extended()
        else:
            logger.debug(
                _("Extended stats for top process is enabled (default behavor)"
                  ))
            glances_processes.enable_extended()

        # Manage optionnal process filter
        if args.process_filter is not None:
            glances_processes.set_process_filter(args.process_filter)

        # Initial system informations update
        self.stats.update()

        # Init CSV output
        if args.output_csv is not None:
            from glances.outputs.glances_csv import GlancesCSV

            self.csvoutput = GlancesCSV(args=args)
            self.csv_tag = True
        else:
            self.csv_tag = False

        # Init screen
        self.screen = GlancesCurses(args=args)
コード例 #2
0
    def __init__(self, config=None, args=None):
        # Init stats
        self.stats = GlancesStats(config=config, args=args)

        # Default number of processes to displayed is set to 50
        glances_processes.set_max_processes(50)

        # If process extended stats is disabled by user
        if args.disable_process_extended:
            logger.info(_("Extended stats for top process is disabled"))
            glances_processes.disable_extended()
        else:
            logger.debug(_("Extended stats for top process is enabled (default behavor)"))
            glances_processes.enable_extended()

        # Manage optionnal process filter
        if args.process_filter is not None:
            glances_processes.set_process_filter(args.process_filter)

        # Initial system informations update
        self.stats.update()

        # Init CSV output
        if args.output_csv is not None:
            from glances.outputs.glances_csv import GlancesCSV

            self.csvoutput = GlancesCSV(args=args)
            self.csv_tag = True
        else:
            self.csv_tag = False

        # Init screen
        self.screen = GlancesCurses(args=args)
コード例 #3
0
    def __init__(self, config=None, args=None):
        # Init stats
        self.stats = GlancesStats(config=config, args=args)

        # If configured, set the maximum processes number to display
        try:
            max_processes = int(
                self.stats.get_plugin('processlist').get_conf_value(
                    'max_processes'))
            logger.debug(
                _("Limit maximum displayed processes to %s") % max_processes)
        except:
            max_processes = None
            logger.warning(
                _("Maximum displayed processes is not configured (high CPU consumption)"
                  ))
        glances_processes.set_max_processes(max_processes)

        # If process extended stats is disabled by user
        if args.disable_process_extended:
            logger.info(_("Extended stats for top process is disabled"))
            glances_processes.disable_extended()
        else:
            logger.debug(
                _("Extended stats for top process is enabled (default behavor)"
                  ))
            glances_processes.enable_extended()

        # Manage optionnal process filter
        if args.process_filter is not None:
            glances_processes.set_process_filter(args.process_filter)

        # Initial system informations update
        self.stats.update()

        # Init CSV output
        if args.output_csv is not None:
            from glances.outputs.glances_csv import GlancesCSV

            self.csvoutput = GlancesCSV(args=args)
            self.csv_tag = True
        else:
            self.csv_tag = False

        # Init screen
        self.screen = GlancesCurses(args=args)
コード例 #4
0
    def __init__(self, config=None, args=None):
        # Init stats
        self.stats = GlancesStats(config=config, args=args)

        # Default number of processes to displayed is set to 50
        glances_processes.set_max_processes(50)

        # If process extended stats is disabled by user
        if not args.enable_process_extended:
            logger.info("Extended stats for top process are disabled (default behavior)")
            glances_processes.disable_extended()
        else:
            logger.debug("Extended stats for top process are enabled")
            glances_processes.enable_extended()

        # Manage optionnal process filter
        if args.process_filter is not None:
            glances_processes.set_process_filter(args.process_filter)

        if (not is_windows) and args.no_kernel_threads:
            # Ignore kernel threads in process list
            glances_processes.disable_kernel_threads()

        if args.process_tree:
            # Enable process tree view
            glances_processes.enable_tree()

        # Initial system informations update
        self.stats.update()

        # Init CSV output
        if args.output_csv is not None:
            from glances.outputs.glances_csv import GlancesCSV

            self.csvoutput = GlancesCSV(args=args)
            self.csv_tag = True
        else:
            self.csv_tag = False

        # Init screen
        self.screen = GlancesCursesStandalone(args=args)
コード例 #5
0
    def __init__(self, config=None, args=None):
        # Init stats
        self.stats = GlancesStats(config=config, args=args)

        # If configured, set the maximum processes number to display
        try:
            max_processes = int(self.stats.get_plugin('processlist').get_conf_value('max_processes'))
            logger.debug(_("Limit maximum displayed processes to %s") % max_processes)
        except:
            max_processes = None
            logger.warning(_("Maximum displayed processes is not configured (high CPU consumption)"))
        glances_processes.set_max_processes(max_processes)

        # If process extended stats is disabled by user
        if args.disable_process_extended:
            logger.info(_("Extended stats for top process is disabled"))
            glances_processes.disable_extended()
        else:
            logger.debug(_("Extended stats for top process is enabled (default behavor)"))
            glances_processes.enable_extended()

        # Manage optionnal process filter
        if args.process_filter is not None:
            glances_processes.set_process_filter(args.process_filter)

        # Initial system informations update
        self.stats.update()

        # Init CSV output
        if args.output_csv is not None:
            from glances.outputs.glances_csv import GlancesCSV

            self.csvoutput = GlancesCSV(args=args)
            self.csv_tag = True
        else:
            self.csv_tag = False

        # Init screen
        self.screen = GlancesCurses(args=args)
コード例 #6
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
コード例 #7
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