diff options
| author | 陆秋文 <[email protected]> | 2024-01-19 09:57:18 +0000 |
|---|---|---|
| committer | 陆秋文 <[email protected]> | 2024-01-19 09:57:18 +0000 |
| commit | ac0a61dc77b42c372cd28f1f014fe46081ed7996 (patch) | |
| tree | 90d22ef9a76762f55b06ab28def58053d8856257 /tools/monit_device | |
| parent | cd77b85573e3e0a6a135310830eaecec7b921af2 (diff) | |
TSG-18269 fix the missing LACP packets and improve the status output of bond interfaces.v4.6.71-20240119
Diffstat (limited to 'tools/monit_device')
| -rwxr-xr-x | tools/monit_device/monit_device.py | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/tools/monit_device/monit_device.py b/tools/monit_device/monit_device.py index c25032f..dc943f2 100755 --- a/tools/monit_device/monit_device.py +++ b/tools/monit_device/monit_device.py @@ -83,17 +83,22 @@ def dump_pkt_latency_prometheus_output(json_fp): resp = '' return resp +def phydev_status_read(json_fp, str_device, str_section, str_item, func=None): + phydevs = locate_vector_by_symbol(json_fp['device'], str_device) + + if func: + return func(phydevs[0][str_section][str_item]) + else: + return phydevs[0][str_section][str_item] def phydev_value_read(json_fp, str_device, str_item): phydevs = locate_vector_by_symbol(json_fp['device'], str_device) return phydevs[0]['stats']['accumulative'][str_item] - def phydev_speed_read(json_fp, str_device, str_item): phydevs = locate_vector_by_symbol(json_fp['device'], str_device) return phydevs[0]['stats']['speed'][str_item] - def trans_to_human_readable(value): if value > TBPS: return value * 1.0 / TBPS, 'T' @@ -152,6 +157,54 @@ def dump_prometheus_output(json_fp, devsym): return resp +STATUS_TITLE_VEC = [ + 'ID', + 'Type', + 'Role', + 'MTU', + 'EtherAddress', + 'Speed', + 'Promisc', + 'Status', +] + +STATUS_TITLE_SECTION_MAP = { + 'ID' : ('information','PortID', None), + 'Type' : ('information','Type', None), + 'Role' : ('information','Role', None), + 'MTU' : ('information','MTU', None), + 'Promisc':('information','Promisc', lambda v: 'ON' if v else 'OFF'), + 'EtherAddress' : ('information', 'EtherAddr', None), + 'Speed' : ('link', 'LinkSpeed', None), + 'Status' : ('link', 'LinkStatus', lambda v: 'UP' if v else 'DOWN') +} + +def dump_device_status_output(json_fp, vec_devsym): + + print('\nTime: %s' % (time.strftime('%c'))) + + table_dev_status = prettytable.PrettyTable(['Device'] + STATUS_TITLE_VEC, + vertical_char=' ', horizontal_char='-', junction_char=' ') + + table_dev_status.align['Device'] = 'l' + + for item in STATUS_TITLE_VEC: + table_dev_status.align[item] = 'l' + + for devsym in vec_devsym: + vec_output_raw = [devsym] + + for item in STATUS_TITLE_VEC: + section_map = STATUS_TITLE_SECTION_MAP[item] + str_output = phydev_status_read(json_fp, devsym, section_map[0], section_map[1], section_map[2]) + vec_output_raw += [str_output] + + table_dev_status.add_row(vec_output_raw) + + print(table_dev_status) + + + def setup_argv_parser(phydev_list): parser = argparse.ArgumentParser( description='Marsio ZeroCopy Tools -- Monitor NIC devices') @@ -164,6 +217,8 @@ def setup_argv_parser(phydev_list): action='store_true', default=0) parser.add_argument('-i', '--interface', help='the name of network interface', action='append', choices=phydev_list) + parser.add_argument('-s', '--status', help='print the status of network interfaces', + action='store_true', default=0) parser.add_argument('--clear-screen', help='clear screen at start of loop', action='store_true', default=0) @@ -234,8 +289,11 @@ def main(): json_fp = phydev_json_load() - for devsym in phydev_user_list: - dump_human_table(json_fp, devsym, r_option.human_readable) + if r_option.status: + dump_device_status_output(json_fp, phydev_user_list) + else: + for devsym in phydev_user_list: + dump_human_table(json_fp, devsym, r_option.human_readable) if not r_option.loop: break |
