diff --git a/conf/glances-monitor.conf b/conf/glances-monitor.conf index dee997cfc8ffa62658589b542480577bff17d95f..ba8a92ef1e3c4eba86184162611ef1d87a12bc5a 100644 --- a/conf/glances-monitor.conf +++ b/conf/glances-monitor.conf @@ -52,6 +52,10 @@ careful=50 warning=70 critical=90 +[network] +# Define the list of hidden network interfaces (comma separeted) +#hide=lo + [temperature] # Temperatures in °C for sensors # Default values if not defined: 60/70/80 @@ -89,10 +93,6 @@ mem_critical=90 # Define the list of hidden disks (comma separeted) #hide=sda2,sda5 -[network] -# Define the list of hidden network interfaces (comma separeted) -#hide=lo - [monitor] # Define the list of processes to monitor # *** This section is optional *** diff --git a/glances/__init__.py b/glances/__init__.py index a3393639bf8c319e27d344047f06052630d9ed41..89fbdfbc2ced7ab9e7c74fb0961488111e3759a3 100644 --- a/glances/__init__.py +++ b/glances/__init__.py @@ -32,7 +32,8 @@ def main(argv=None): from .core.glances_standalone import GlancesStandalone # Init the standalone mode - standalone = GlancesStandalone(config=core.config, + standalone = GlancesStandalone(config=core.get_config(), + args=core.get_args(), refresh_time=core.refresh_time, use_bold=core.use_bold) diff --git a/glances/core/glances_main.py b/glances/core/glances_main.py index ad0df71ad9560159cbb6de1ee2c8215894cec617..ae2f00ab68c6a2f723eae905bdb199ee29117379 100644 --- a/glances/core/glances_main.py +++ b/glances/core/glances_main.py @@ -78,7 +78,7 @@ class GlancesMain(object): def __init__(self): # Init and manage command line arguments self.init_arg() - self.parse_arg() + self.args = self.parse_arg() # Read the configuration file if (self.conf_file_tag): @@ -220,6 +220,7 @@ class GlancesMain(object): self.parser.add_argument('-f', '--file', help=_('set the html output folder or csv file')) + def parse_arg(self): """ Parse command line argument @@ -227,7 +228,10 @@ class GlancesMain(object): args = self.parser.parse_args() - # Change global variables regarding to user args + # Default refresh time is 3 seconds + if (args.time is None): args.time = 3 + + # !!! Change global variables regarding to user args # !!! To be refactor to use directly the args list in the code if (args.time is not None): self.refresh_time = args.time self.network_bytepersec_tag = args.byte @@ -263,9 +267,10 @@ class GlancesMain(object): if (args.file is not None): output_file = args.file output_folder = args.file + # /!!! + + return args - # !!! Debug - # print args def __get_password(self, description='', confirm=False): """ @@ -288,26 +293,37 @@ class GlancesMain(object): sys.stdout.write(_("[Warning] Passwords did not match, please try again...\n")) return self.__get_password(description=description, confirm=confirm) + def is_standalone(self): """ Return True if Glances is running in standalone mode """ return not self.client_tag and not self.server_tag + def is_client(self): """ Return True if Glances is running in client mode """ return self.client_tag and not self.server_tag + def is_server(self): """ Return True if Glances is running in sserver mode """ return not self.client_tag and self.server_tag + def get_config(self): """ Return configuration file object """ return self.config + + + def get_args(self): + """ + Return the arguments + """ + return self.args \ No newline at end of file diff --git a/glances/core/glances_standalone.py b/glances/core/glances_standalone.py index 0bf45f7b508f8d57be2a00f920afe870f5b3d55b..40fab08fea3b2d8a111c811868b3918073362c9d 100644 --- a/glances/core/glances_standalone.py +++ b/glances/core/glances_standalone.py @@ -37,6 +37,7 @@ class GlancesStandalone(): def __init__(self, config=None, + args=None, refresh_time=3, use_bold=True): # Init the limits @@ -52,7 +53,7 @@ class GlancesStandalone(): # !!! The first time Glances display wrong CPU information self.stats.update() - self.refresh_time = refresh_time + self.refresh_time = args.time # Init HTML output # !!! TODO @@ -67,10 +68,7 @@ class GlancesStandalone(): # refresh_time=refresh_time) # Init screen - # !!! TODO - # !!! Is refresh_time mandatory for this class ? - self.screen = glancesCurses(refresh_time=refresh_time, - use_bold=use_bold) + self.screen = glancesCurses(args=args) def serve_forever(self): diff --git a/glances/core/glances_stats.py b/glances/core/glances_stats.py index fe793db3cb5cc8940b57a2a4694693328edee786..a01941367c1c84ffbae9c2bb5ae86a32b62cf073 100644 --- a/glances/core/glances_stats.py +++ b/glances/core/glances_stats.py @@ -52,7 +52,6 @@ class GlancesStats(object): Overwrite the getattr in case of attribute is not found The goal is to dynamicaly generate the following methods: - getPlugname(): return Plugname stat in JSON format - - cursePlugname(): return Plugname stat in STR (for curses) """ # Check if the attribute starts with 'get' @@ -67,17 +66,6 @@ class GlancesStats(object): else: # The method get_stats is not found for the plugin raise AttributeError(item) - elif (item.startswith('curse')): - # Get the plugin name - plugname = item[len('curse'):].lower() - # Get the plugin instance - plugin = self._plugins[plugname] - if (hasattr(plugin, 'get_curse')): - # The method get_curse exist, return it - return getattr(plugin, 'get_curse') - else: - # The method get_curse is not found for the plugin - raise AttributeError(item) else: # Default behavior raise AttributeError(item) @@ -130,6 +118,19 @@ class GlancesStats(object): self.__update__(input_stats) + def get_plugin_list(self): + # Return the plugin list + self._plugins + + + def get_plugin(self, plugin_name): + # Return the plugin name + if (plugin_name in self._plugins): + return self._plugins[plugin_name] + else: + return None + + class GlancesStatsServer(GlancesStats): def __init__(self): diff --git a/glances/plugins/glances_cpu.py b/glances/plugins/glances_cpu.py index 8b2b31b9ac74adfc4e1611bd7e67ba652c909040..8d78e111c150ac21037194524a87e0462cf7adca 100644 --- a/glances/plugins/glances_cpu.py +++ b/glances/plugins/glances_cpu.py @@ -104,7 +104,7 @@ class Plugin(GlancesPlugin): return self.stats - def msg_curse(self): + def msg_curse(self, args=None): """ Return the dict to display in the curse interface """ diff --git a/glances/plugins/glances_load.py b/glances/plugins/glances_load.py index 4f1bc0a1815bfd6e788d9e303de703071fbbbb36..5fe8e83652a8b86821c25bd34b64fa176e19a16e 100644 --- a/glances/plugins/glances_load.py +++ b/glances/plugins/glances_load.py @@ -65,7 +65,7 @@ class Plugin(GlancesPlugin): return self.stats - def msg_curse(self): + def msg_curse(self, args=None): """ Return the dict to display in the curse interface """ diff --git a/glances/plugins/glances_mem.py b/glances/plugins/glances_mem.py index efbfbe318c3b3ba666085e3b99c4d93b4796fac3..35254caabb3829109f25325e2e31df813b2fa86e 100644 --- a/glances/plugins/glances_mem.py +++ b/glances/plugins/glances_mem.py @@ -101,7 +101,7 @@ class Plugin(GlancesPlugin): self.stats = {} - def msg_curse(self): + def msg_curse(self, args=None): """ Return the dict to display in the curse interface """ diff --git a/glances/plugins/glances_memswap.py b/glances/plugins/glances_memswap.py index ff5d662228e03def38e2a7ef819e3fb441c4663b..198319483d1ecbc26812618249c9343daf2632e7 100644 --- a/glances/plugins/glances_memswap.py +++ b/glances/plugins/glances_memswap.py @@ -75,7 +75,7 @@ class Plugin(GlancesPlugin): self.stats = {} - def msg_curse(self): + def msg_curse(self, args=None): """ Return the dict to display in the curse interface """ diff --git a/glances/plugins/glances_network.py b/glances/plugins/glances_network.py index daefdd44684176609126183bc85f86fac37f93b5..5f54ebcefabe992a2657b70975ffa934f119bedb 100644 --- a/glances/plugins/glances_network.py +++ b/glances/plugins/glances_network.py @@ -44,6 +44,15 @@ class Plugin(GlancesPlugin): def __init__(self): GlancesPlugin.__init__(self) + # We want to display the stat in the curse interface + self.display_curse = True + # Set the message position + # It is NOT the curse position but the Glances column/line + # Enter -1 to right align + self.column_curse = 0 + # Enter -1 to diplay bottom + self.line_curse = 2 + def update(self): """ @@ -100,8 +109,37 @@ class Plugin(GlancesPlugin): self.stats = network - def get_stats(self): - # Return the stats object for the RPC API - # !!! Sort it by interface name (why do it here ? Better in client side ?) - self.stats = sorted(self.stats, key=lambda network: network['interface_name']) - return GlancesPlugin.get_stats(self) + def msg_curse(self, args=None): + """ + Return the dict to display in the curse interface + """ + # Init the return message + ret = [] + + # Build the string message + # Header + msg = "{0:6}".format(_("NETWORK")) + ret.append(self.curse_add_line(msg, "TITLE")) + msg = "{0:>7} {1:>7}".format(_("Rx/s"), _("Tx/s")) + ret.append(self.curse_add_line(msg)) + # Interface list (sorted by name) + for i in sorted(self.stats, key=lambda network: network['interface_name']): + # Format stats + ifname = i['interface_name'].split(':')[0] + if (args.byte): + rxps = self.auto_unit(int(i['rx'] // i['time_since_update'])) + txps = self.auto_unit(int(i['tx'] // i['time_since_update'])) + else: + rxps = self.auto_unit(int(i['rx'] // i['time_since_update'] * 8)) + "b" + txps = self.auto_unit(int(i['tx'] // i['time_since_update'] * 8)) + "b" + + # !!! TODO: manage the hide tag + + # New line + ret.append(self.curse_new_line()) + msg = "{0:7}".format(ifname) + ret.append(self.curse_add_line(msg)) + msg = "{0:>7} {1:>7}".format(rxps, txps) + ret.append(self.curse_add_line(msg)) + + return ret diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index 1f703fe666953300b21ff19415164eeae8f044d1..2e4d186bb41178615ac92715febd2ddb1d86f1ee 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -155,14 +155,14 @@ class GlancesPlugin(object): return self.limits[self.plugin_name + '_' + 'careful'] - def msg_curse(self): + def msg_curse(self, args): """ Return default string to display in the curse interface """ return [ self.curse_add_line(str(self.stats)) ] - def get_curse(self): + def get_curse(self, args=None): # Return a dict with all the information needed to display the stat # key | description #---------------------------- @@ -183,7 +183,7 @@ class GlancesPlugin(object): line_curse = self.line_curse return { 'display': display_curse, - 'msgdict': self.msg_curse(), + 'msgdict': self.msg_curse(args), 'column': column_curse, 'line': line_curse } diff --git a/glances/plugins/glances_system.py b/glances/plugins/glances_system.py index 8c8e03788ad57b3edda1eef0f043bca2c1436d13..29eff3f2deb9455786e92d685a00afc5fd9e06ff 100644 --- a/glances/plugins/glances_system.py +++ b/glances/plugins/glances_system.py @@ -72,7 +72,7 @@ class Plugin(GlancesPlugin): self.stats['os_version'] = "" - def msg_curse(self): + def msg_curse(self, args=None): """ Return the string to display in the curse interface """ diff --git a/glances/plugins/glances_uptime.py b/glances/plugins/glances_uptime.py index deac01ad7fb460bacd8e10af6c5e7666d45676fa..637f7e743b14c1209c7315f1beae1d20a8cc1967 100644 --- a/glances/plugins/glances_uptime.py +++ b/glances/plugins/glances_uptime.py @@ -67,7 +67,7 @@ class Plugin(GlancesPlugin): self.stats = str(self.uptime).split('.')[0] - def msg_curse(self): + def msg_curse(self, args=None): """ Return the string to display in the curse interface """