mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-25 02:02:32 +03:00
Manage args between all module
This commit is contained in:
parent
85be3bb603
commit
5c4d3eca4d
@ -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 ***
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -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
|
||||
|
@ -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 }
|
||||
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -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
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user