Merge branch 'issue2741' into develop

This commit is contained in:
nicolargo 2024-05-01 13:45:30 +02:00
commit a146345978
13 changed files with 56 additions and 42 deletions

View File

@ -121,7 +121,7 @@ Optional dependencies:
- ``pygal`` (for the graph export module) - ``pygal`` (for the graph export module)
- ``pymdstat`` (for RAID support) [Linux-only] - ``pymdstat`` (for RAID support) [Linux-only]
- ``pymongo`` (for the MongoDB export module) - ``pymongo`` (for the MongoDB export module)
- ``pysnmp`` (for SNMP support) - ``pysnmp-lextudio`` (for SNMP support)
- ``pySMART.smartx`` (for HDD Smart support) [Linux-only] - ``pySMART.smartx`` (for HDD Smart support) [Linux-only]
- ``pyzmq`` (for the ZeroMQ export module) - ``pyzmq`` (for the ZeroMQ export module)
- ``requests`` (for the Ports, Cloud plugins and RESTful export module) - ``requests`` (for the Ports, Cloud plugins and RESTful export module)

View File

@ -106,30 +106,46 @@ class PluginModel(GlancesPluginModel):
('toggle_linux_percentage', msg_col.format('0', 'Load, Linux/percentage')), ('toggle_linux_percentage', msg_col.format('0', 'Load, Linux/percentage')),
('toggle_cpu_individual_combined', msg_col.format('1', 'CPU, individual/combined')), ('toggle_cpu_individual_combined', msg_col.format('1', 'CPU, individual/combined')),
('toggle_gpu_individual_combined', msg_col.format('6', 'GPU, individual/combined')), ('toggle_gpu_individual_combined', msg_col.format('6', 'GPU, individual/combined')),
('toggle_short_full', (
msg_col.format('S', 'toggle_short_full',
'Process names, short/full') if self.args.webserver else msg_col.format('/', 'Process names, short/full')), (
msg_col.format('S', 'Process names, short/full')
if self.args and self.args.webserver
else msg_col.format('/', 'Process names, short/full')
),
),
('header_miscellaneous', msg_header.format('MISCELLANEOUS:')), ('header_miscellaneous', msg_header.format('MISCELLANEOUS:')),
('misc_erase_process_filter', (
'' if self.args.webserver else msg_col.format('E', 'Erase process filter')), 'misc_erase_process_filter',
('misc_generate_history_graphs', '' if self.args and self.args.webserver else msg_col.format('E', 'Erase process filter'),
'' if self.args.webserver else msg_col.format('g', 'Generate history graphs')), ),
(
'misc_generate_history_graphs',
'' if self.args and self.args.webserver else msg_col.format('g', 'Generate history graphs'),
),
('misc_help', msg_col.format('h', 'HELP')), ('misc_help', msg_col.format('h', 'HELP')),
('misc_accumulate_processes_by_program', (
'' if self.args.webserver else msg_col.format('j', 'Display threads or programs')), 'misc_accumulate_processes_by_program',
'' if self.args and self.args.webserver else msg_col.format('j', 'Display threads or programs'),
),
('misc_increase_nice_process', msg_col.format('+', 'Increase nice process')), ('misc_increase_nice_process', msg_col.format('+', 'Increase nice process')),
('misc_decrease_nice_process', msg_col.format('-', 'Decrease nice process (need admin rights)')), ('misc_decrease_nice_process', msg_col.format('-', 'Decrease nice process (need admin rights)')),
('misc_kill_process', ('misc_kill_process', '' if self.args and self.args.webserver else msg_col.format('k', 'Kill process')),
'' if self.args.webserver else msg_col.format('k', 'Kill process')), (
('misc_reset_processes_summary_min_max', 'misc_reset_processes_summary_min_max',
'' if self.args.webserver else msg_col.format('M', 'Reset processes summary min/max')), '' if self.args and self.args.webserver else msg_col.format('M', 'Reset processes summary min/max'),
('misc_quit', ),
'' if self.args.webserver else msg_col.format('q', 'QUIT (or Esc or Ctrl-C)')), (
'misc_quit',
'' if self.args and self.args.webserver else msg_col.format('q', 'QUIT (or Esc or Ctrl-C)'),
),
('misc_reset_history', msg_col.format('r', 'Reset history')), ('misc_reset_history', msg_col.format('r', 'Reset history')),
('misc_delete_warning_alerts', msg_col.format('w', 'Delete warning alerts')), ('misc_delete_warning_alerts', msg_col.format('w', 'Delete warning alerts')),
('misc_delete_warning_and_critical_alerts', msg_col.format('x', 'Delete warning & critical alerts')), ('misc_delete_warning_and_critical_alerts', msg_col.format('x', 'Delete warning & critical alerts')),
('misc_edit_process_filter_pattern', (
'' if self.args.webserver else ' ENTER: Edit process filter pattern'), 'misc_edit_process_filter_pattern',
'' if self.args and self.args.webserver else ' ENTER: Edit process filter pattern',
),
] ]
) )

View File

@ -204,12 +204,8 @@ class PluginModel(GlancesPluginModel):
self.reset() self.reset()
return self.stats return self.stats
for key in iterkeys(stats): for k in stats:
if stats[key] != '': stats[k] = int(stats[k]) * 1024
stats[key] = float(stats[key]) * 1024
# Use the 'free'/htop calculation
stats['free'] = stats['free'] - stats['total'] + (stats['buffers'] + stats['cached'])
# used=total-free # used=total-free
stats['used'] = stats['total'] - stats['free'] stats['used'] = stats['total'] - stats['free']

View File

@ -53,9 +53,9 @@ class PluginModel(GlancesPluginModel):
# Set the message position # Set the message position
self.align = 'bottom' self.align = 'bottom'
if args.strftime_format: if args and args.strftime_format:
self.strftime = args.strftime_format self.strftime = args.strftime_format
elif config is not None: elif config:
if 'global' in config.as_dict(): if 'global' in config.as_dict():
self.strftime = config.as_dict()['global']['strftime_format'] self.strftime = config.as_dict()['global']['strftime_format']

View File

@ -108,7 +108,10 @@ class PluginModel(GlancesPluginModel):
self.display_curse = True self.display_curse = True
# Manage the maximum number of CPU to display (related to enhancement request #2734) # Manage the maximum number of CPU to display (related to enhancement request #2734)
if config:
self.max_cpu_display = config.get_int_value('percpu', 'max_cpu_display', 4) self.max_cpu_display = config.get_int_value('percpu', 'max_cpu_display', 4)
else:
self.max_cpu_display = 4
def get_key(self): def get_key(self):
"""Return the key of the list.""" """Return the key of the list."""

View File

@ -350,8 +350,10 @@ class GlancesPluginModel(object):
ret = {} ret = {}
if bulk: if bulk:
# Bulk request # Bulk request
snmp_result = snmp_client.getbulk_by_oid(0, 10, itervalues(*snmp_oid)) snmp_result = snmp_client.getbulk_by_oid(0,
10,
*list(itervalues(snmp_oid)))
logger.info(snmp_result)
if len(snmp_oid) == 1: if len(snmp_oid) == 1:
# Bulk command for only one OID # Bulk command for only one OID
# Note: key is the item indexed but the OID result # Note: key is the item indexed but the OID result
@ -379,7 +381,7 @@ class GlancesPluginModel(object):
index += 1 index += 1
else: else:
# Simple get request # Simple get request
snmp_result = snmp_client.get_by_oid(itervalues(*snmp_oid)) snmp_result = snmp_client.get_by_oid(*list(itervalues(snmp_oid)))
# Build the internal dict with the SNMP result # Build the internal dict with the SNMP result
for key in iterkeys(snmp_oid): for key in iterkeys(snmp_oid):
@ -623,7 +625,7 @@ class GlancesPluginModel(object):
"""Return the plugin refresh time""" """Return the plugin refresh time"""
ret = self.get_limits(item='refresh') ret = self.get_limits(item='refresh')
if ret is None: if ret is None:
ret = self.args.time ret = self.args.time if hasattr(self.args, 'time') else 2
return ret return ret
def get_refresh_time(self): def get_refresh_time(self):

View File

@ -194,7 +194,7 @@ class PluginModel(GlancesPluginModel):
config.as_dict()['processlist']['export'])) config.as_dict()['processlist']['export']))
# The default sort key could also be overwrite by command line (see #1903) # The default sort key could also be overwrite by command line (see #1903)
if args.sort_processes_key is not None: if args and args.sort_processes_key is not None:
glances_processes.set_sort_key(args.sort_processes_key, False) glances_processes.set_sort_key(args.sort_processes_key, False)
# Note: 'glances_processes' is already init in the processes.py script # Note: 'glances_processes' is already init in the processes.py script

View File

@ -92,7 +92,7 @@ class PluginModel(GlancesPluginModel):
self.display_curse = True self.display_curse = True
# Manage the maximum number of CPU to display (related to enhancement request #2734) # Manage the maximum number of CPU to display (related to enhancement request #2734)
self.max_cpu_display = config.get_int_value('percpu', 'max_cpu_display', 4) self.max_cpu_display = config.get_int_value('percpu', 'max_cpu_display', 4) if config else 4
# Define the stats list # Define the stats list
self.stats_list = self.get_conf_value('list', default=self.DEFAULT_STATS_LIST) self.stats_list = self.get_conf_value('list', default=self.DEFAULT_STATS_LIST)

View File

@ -101,7 +101,7 @@ class PluginModel(GlancesPluginModel):
self.display_curse = True self.display_curse = True
# Not necessary to refresh every refresh time # Not necessary to refresh every refresh time
if self.get_refresh() == args.time: if args and self.get_refresh() == args.time:
self.set_refresh(self.get_refresh() * DEFAULT_REFRESH) self.set_refresh(self.get_refresh() * DEFAULT_REFRESH)
def get_key(self): def get_key(self):

View File

@ -125,7 +125,7 @@ class PluginModel(GlancesPluginModel):
def __init__(self, args=None, config=None, stats_init_value=[]): def __init__(self, args=None, config=None, stats_init_value=[]):
"""Init the plugin.""" """Init the plugin."""
# check if user is admin # check if user is admin
if not is_admin(): if not is_admin() and args:
disable(args, "smart") disable(args, "smart")
logger.debug("Current user is not admin, HDD SMART plugin disabled.") logger.debug("Current user is not admin, HDD SMART plugin disabled.")

View File

@ -132,7 +132,7 @@ class PluginModel(GlancesPluginModel):
self.set_refresh(60) self.set_refresh(60)
# Get the default message (if defined) # Get the default message (if defined)
self.system_info_msg = config.get_value('system', 'system_info_msg') self.system_info_msg = config.get_value('system', 'system_info_msg') if config else None
@GlancesPluginModel._check_decorator @GlancesPluginModel._check_decorator
@GlancesPluginModel._log_result_decorator @GlancesPluginModel._log_result_decorator

View File

@ -41,12 +41,9 @@ class GlancesSNMPClient(object):
ret = {} ret = {}
for name, val in varBinds: for name, val in varBinds:
if str(val) == '': if str(val) == '':
ret[name.prettyPrint()] = '' ret[str(name)] = ''
else: else:
ret[name.prettyPrint()] = val.prettyPrint() ret[str(name)] = val.prettyPrint()
# In Python 3, prettyPrint() return 'b'linux'' instead of 'linux'
if ret[name.prettyPrint()].startswith('b\''):
ret[name.prettyPrint()] = ret[name.prettyPrint()][2:-1]
return ret return ret
def __get_result__(self, errorIndication, errorStatus, errorIndex, varBinds): def __get_result__(self, errorIndication, errorStatus, errorIndex, varBinds):

View File

@ -27,7 +27,7 @@ pygal
pymdstat pymdstat
pymongo; python_version >= "3.7" pymongo; python_version >= "3.7"
nvidia-ml-py; python_version >= "3.5" nvidia-ml-py; python_version >= "3.5"
pysnmp pysnmp-lextudio; python_version >= "3.7"
pySMART.smartx pySMART.smartx
python-dateutil python-dateutil
pyzmq pyzmq