Add network

This commit is contained in:
nicolargo 2021-07-15 11:16:29 +02:00
parent dad4d2846d
commit 1865384954
2 changed files with 38 additions and 2 deletions

View File

@ -49,7 +49,7 @@ class GlancesStdoutFieldsDescription(object):
print('Restfull/API plugins documentation')
print('==================================')
print('')
print('The Glanes Restfull/API server could be ran using the following command line:')
print('The Glances Restfull/API server could be ran using the following command line:')
print('')
print('.. code-block:: bash')
print('')
@ -70,7 +70,12 @@ class GlancesStdoutFieldsDescription(object):
print('.. code-block:: json')
print('')
print(' # curl http://localhost:61208/api/3/{}'.format(plugin))
print(' ' + pformat(stats._plugins[plugin].get_export()).replace('\n', '\n '))
stat = stats._plugins[plugin].get_export()
if isinstance(stat, list) and len(stat) > 1:
# Only display two first items
print(' ' + pformat(stat[0:2]).replace('\n', '\n '))
else:
print(' ' + pformat(stat).replace('\n', '\n '))
print('')
else:
logger.error('No fields_description variable defined for plugin {}'.format(plugin))

View File

@ -29,6 +29,36 @@ from glances.logger import logger
import psutil
# {'interface_name': 'mpqemubr0-dummy',
# 'alias': None,
# 'time_since_update': 2.081636428833008,
# 'cumulative_rx': 0,
# 'rx': 0, 'cumulative_tx': 0, 'tx': 0, 'cumulative_cx': 0, 'cx': 0,
# 'is_up': False,
# 'speed': 0,
# 'key': 'interface_name'}
# Fields description
fields_description = {
'interface_name': {'description': 'Interface name.',
'unit': 'string'},
'alias': {'description': 'Interface alias name (optional).',
'unit': 'string'},
'rx': {'description': 'The received/input rate (in bit per second).',
'unit': 'bps'},
'tx': {'description': 'The sent/output rate (in bit per second).',
'unit': 'bps'},
'cumulative_rx': {'description': 'The number of bytes received through the interface (cumulative).',
'unit': 'bytes'},
'cumulative_tx': {'description': 'The number of bytes sent through the interface (cumulative).',
'unit': 'bytes'},
'speed': {'description': 'Maximum interface speed (in bit per second). Can return 0 on some operating-system.',
'unit': 'bps'},
'is_up': {'description': 'Is the interface up ?',
'unit': 'bool'},
'time_since_update': {'description': 'Number of seconds since last update.',
'unit': 'seconds'},
}
# SNMP OID
# http://www.net-snmp.org/docs/mibs/interfaces.html
# Dict key = interface_name
@ -56,6 +86,7 @@ class Plugin(GlancesPlugin):
super(Plugin, self).__init__(args=args,
config=config,
items_history_list=items_history_list,
fields_description=fields_description,
stats_init_value=[])
# We want to display the stat in the curse interface