提交 5c4d3eca 编写于 作者: N Nicolas Hennion

Manage args between all module

上级 85be3bb6
...@@ -52,6 +52,10 @@ careful=50 ...@@ -52,6 +52,10 @@ careful=50
warning=70 warning=70
critical=90 critical=90
[network]
# Define the list of hidden network interfaces (comma separeted)
#hide=lo
[temperature] [temperature]
# Temperatures in °C for sensors # Temperatures in °C for sensors
# Default values if not defined: 60/70/80 # Default values if not defined: 60/70/80
...@@ -89,10 +93,6 @@ mem_critical=90 ...@@ -89,10 +93,6 @@ mem_critical=90
# Define the list of hidden disks (comma separeted) # Define the list of hidden disks (comma separeted)
#hide=sda2,sda5 #hide=sda2,sda5
[network]
# Define the list of hidden network interfaces (comma separeted)
#hide=lo
[monitor] [monitor]
# Define the list of processes to monitor # Define the list of processes to monitor
# *** This section is optional *** # *** This section is optional ***
......
...@@ -32,7 +32,8 @@ def main(argv=None): ...@@ -32,7 +32,8 @@ def main(argv=None):
from .core.glances_standalone import GlancesStandalone from .core.glances_standalone import GlancesStandalone
# Init the standalone mode # Init the standalone mode
standalone = GlancesStandalone(config=core.config, standalone = GlancesStandalone(config=core.get_config(),
args=core.get_args(),
refresh_time=core.refresh_time, refresh_time=core.refresh_time,
use_bold=core.use_bold) use_bold=core.use_bold)
......
...@@ -78,7 +78,7 @@ class GlancesMain(object): ...@@ -78,7 +78,7 @@ class GlancesMain(object):
def __init__(self): def __init__(self):
# Init and manage command line arguments # Init and manage command line arguments
self.init_arg() self.init_arg()
self.parse_arg() self.args = self.parse_arg()
# Read the configuration file # Read the configuration file
if (self.conf_file_tag): if (self.conf_file_tag):
...@@ -220,6 +220,7 @@ class GlancesMain(object): ...@@ -220,6 +220,7 @@ class GlancesMain(object):
self.parser.add_argument('-f', '--file', self.parser.add_argument('-f', '--file',
help=_('set the html output folder or csv file')) help=_('set the html output folder or csv file'))
def parse_arg(self): def parse_arg(self):
""" """
Parse command line argument Parse command line argument
...@@ -227,7 +228,10 @@ class GlancesMain(object): ...@@ -227,7 +228,10 @@ class GlancesMain(object):
args = self.parser.parse_args() 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 # !!! To be refactor to use directly the args list in the code
if (args.time is not None): self.refresh_time = args.time if (args.time is not None): self.refresh_time = args.time
self.network_bytepersec_tag = args.byte self.network_bytepersec_tag = args.byte
...@@ -263,9 +267,10 @@ class GlancesMain(object): ...@@ -263,9 +267,10 @@ class GlancesMain(object):
if (args.file is not None): if (args.file is not None):
output_file = args.file output_file = args.file
output_folder = args.file output_folder = args.file
# /!!!
return args
# !!! Debug
# print args
def __get_password(self, description='', confirm=False): def __get_password(self, description='', confirm=False):
""" """
...@@ -288,26 +293,37 @@ class GlancesMain(object): ...@@ -288,26 +293,37 @@ class GlancesMain(object):
sys.stdout.write(_("[Warning] Passwords did not match, please try again...\n")) sys.stdout.write(_("[Warning] Passwords did not match, please try again...\n"))
return self.__get_password(description=description, confirm=confirm) return self.__get_password(description=description, confirm=confirm)
def is_standalone(self): def is_standalone(self):
""" """
Return True if Glances is running in standalone mode Return True if Glances is running in standalone mode
""" """
return not self.client_tag and not self.server_tag return not self.client_tag and not self.server_tag
def is_client(self): def is_client(self):
""" """
Return True if Glances is running in client mode Return True if Glances is running in client mode
""" """
return self.client_tag and not self.server_tag return self.client_tag and not self.server_tag
def is_server(self): def is_server(self):
""" """
Return True if Glances is running in sserver mode Return True if Glances is running in sserver mode
""" """
return not self.client_tag and self.server_tag return not self.client_tag and self.server_tag
def get_config(self): def get_config(self):
""" """
Return configuration file object Return configuration file object
""" """
return self.config return self.config
def get_args(self):
"""
Return the arguments
"""
return self.args
\ No newline at end of file
...@@ -37,6 +37,7 @@ class GlancesStandalone(): ...@@ -37,6 +37,7 @@ class GlancesStandalone():
def __init__(self, def __init__(self,
config=None, config=None,
args=None,
refresh_time=3, refresh_time=3,
use_bold=True): use_bold=True):
# Init the limits # Init the limits
...@@ -52,7 +53,7 @@ class GlancesStandalone(): ...@@ -52,7 +53,7 @@ class GlancesStandalone():
# !!! The first time Glances display wrong CPU information # !!! The first time Glances display wrong CPU information
self.stats.update() self.stats.update()
self.refresh_time = refresh_time self.refresh_time = args.time
# Init HTML output # Init HTML output
# !!! TODO # !!! TODO
...@@ -67,10 +68,7 @@ class GlancesStandalone(): ...@@ -67,10 +68,7 @@ class GlancesStandalone():
# refresh_time=refresh_time) # refresh_time=refresh_time)
# Init screen # Init screen
# !!! TODO self.screen = glancesCurses(args=args)
# !!! Is refresh_time mandatory for this class ?
self.screen = glancesCurses(refresh_time=refresh_time,
use_bold=use_bold)
def serve_forever(self): def serve_forever(self):
......
...@@ -52,7 +52,6 @@ class GlancesStats(object): ...@@ -52,7 +52,6 @@ class GlancesStats(object):
Overwrite the getattr in case of attribute is not found Overwrite the getattr in case of attribute is not found
The goal is to dynamicaly generate the following methods: The goal is to dynamicaly generate the following methods:
- getPlugname(): return Plugname stat in JSON format - getPlugname(): return Plugname stat in JSON format
- cursePlugname(): return Plugname stat in STR (for curses)
""" """
# Check if the attribute starts with 'get' # Check if the attribute starts with 'get'
...@@ -67,17 +66,6 @@ class GlancesStats(object): ...@@ -67,17 +66,6 @@ class GlancesStats(object):
else: else:
# The method get_stats is not found for the plugin # The method get_stats is not found for the plugin
raise AttributeError(item) 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: else:
# Default behavior # Default behavior
raise AttributeError(item) raise AttributeError(item)
...@@ -130,6 +118,19 @@ class GlancesStats(object): ...@@ -130,6 +118,19 @@ class GlancesStats(object):
self.__update__(input_stats) 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): class GlancesStatsServer(GlancesStats):
def __init__(self): def __init__(self):
......
...@@ -104,7 +104,7 @@ class Plugin(GlancesPlugin): ...@@ -104,7 +104,7 @@ class Plugin(GlancesPlugin):
return self.stats return self.stats
def msg_curse(self): def msg_curse(self, args=None):
""" """
Return the dict to display in the curse interface Return the dict to display in the curse interface
""" """
......
...@@ -65,7 +65,7 @@ class Plugin(GlancesPlugin): ...@@ -65,7 +65,7 @@ class Plugin(GlancesPlugin):
return self.stats return self.stats
def msg_curse(self): def msg_curse(self, args=None):
""" """
Return the dict to display in the curse interface Return the dict to display in the curse interface
""" """
......
...@@ -101,7 +101,7 @@ class Plugin(GlancesPlugin): ...@@ -101,7 +101,7 @@ class Plugin(GlancesPlugin):
self.stats = {} self.stats = {}
def msg_curse(self): def msg_curse(self, args=None):
""" """
Return the dict to display in the curse interface Return the dict to display in the curse interface
""" """
......
...@@ -75,7 +75,7 @@ class Plugin(GlancesPlugin): ...@@ -75,7 +75,7 @@ class Plugin(GlancesPlugin):
self.stats = {} self.stats = {}
def msg_curse(self): def msg_curse(self, args=None):
""" """
Return the dict to display in the curse interface Return the dict to display in the curse interface
""" """
......
...@@ -44,6 +44,15 @@ class Plugin(GlancesPlugin): ...@@ -44,6 +44,15 @@ class Plugin(GlancesPlugin):
def __init__(self): def __init__(self):
GlancesPlugin.__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): def update(self):
""" """
...@@ -100,8 +109,37 @@ class Plugin(GlancesPlugin): ...@@ -100,8 +109,37 @@ class Plugin(GlancesPlugin):
self.stats = network self.stats = network
def get_stats(self): def msg_curse(self, args=None):
# Return the stats object for the RPC API """
# !!! Sort it by interface name (why do it here ? Better in client side ?) Return the dict to display in the curse interface
self.stats = sorted(self.stats, key=lambda network: network['interface_name']) """
return GlancesPlugin.get_stats(self) # 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
...@@ -155,14 +155,14 @@ class GlancesPlugin(object): ...@@ -155,14 +155,14 @@ class GlancesPlugin(object):
return self.limits[self.plugin_name + '_' + 'careful'] 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 default string to display in the curse interface
""" """
return [ self.curse_add_line(str(self.stats)) ] 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 # Return a dict with all the information needed to display the stat
# key | description # key | description
#---------------------------- #----------------------------
...@@ -183,7 +183,7 @@ class GlancesPlugin(object): ...@@ -183,7 +183,7 @@ class GlancesPlugin(object):
line_curse = self.line_curse line_curse = self.line_curse
return { 'display': display_curse, return { 'display': display_curse,
'msgdict': self.msg_curse(), 'msgdict': self.msg_curse(args),
'column': column_curse, 'column': column_curse,
'line': line_curse } 'line': line_curse }
......
...@@ -72,7 +72,7 @@ class Plugin(GlancesPlugin): ...@@ -72,7 +72,7 @@ class Plugin(GlancesPlugin):
self.stats['os_version'] = "" self.stats['os_version'] = ""
def msg_curse(self): def msg_curse(self, args=None):
""" """
Return the string to display in the curse interface Return the string to display in the curse interface
""" """
......
...@@ -67,7 +67,7 @@ class Plugin(GlancesPlugin): ...@@ -67,7 +67,7 @@ class Plugin(GlancesPlugin):
self.stats = str(self.uptime).split('.')[0] 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 Return the string to display in the curse interface
""" """
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册