summaryrefslogtreecommitdiff
path: root/src/op_mode/show_interfaces.py
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-03-29 21:11:59 +0200
committerGitHub <noreply@github.com>2023-03-29 21:11:59 +0200
commit589e25721b4df2fceaafd9946dc0c3ccbc37d8d9 (patch)
tree40d29299ce921255b4ddb85db6c8d89c80d91f45 /src/op_mode/show_interfaces.py
parent05ecf032c61953f71c208c184fb77480323bf2a6 (diff)
parente083e64692d69c6eac386871a60dce05e5445db2 (diff)
downloadvyos-1x-589e25721b4df2fceaafd9946dc0c3ccbc37d8d9.tar.gz
vyos-1x-589e25721b4df2fceaafd9946dc0c3ccbc37d8d9.zip
Merge pull request #1912 from jestabro/eq-counters
op-mode: T5097: show interfaces should reflect cleared counters
Diffstat (limited to 'src/op_mode/show_interfaces.py')
-rwxr-xr-xsrc/op_mode/show_interfaces.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/op_mode/show_interfaces.py b/src/op_mode/show_interfaces.py
index 281d25e30..62cb2cdef 100755
--- a/src/op_mode/show_interfaces.py
+++ b/src/op_mode/show_interfaces.py
@@ -20,6 +20,7 @@ import re
import sys
import glob
import argparse
+from tabulate import tabulate
from vyos.ifconfig import Section
from vyos.ifconfig import Interface
@@ -158,6 +159,30 @@ def pppoe(ifname):
return 'D'
return ''
+def _format_stats(stats, indent=4):
+ stat_names = {
+ 'rx': ['bytes', 'packets', 'errors', 'dropped', 'overrun', 'mcast'],
+ 'tx': ['bytes', 'packets', 'errors', 'dropped', 'carrier', 'collisions'],
+ }
+
+ stats_dir = {
+ 'rx': ['rx_bytes', 'rx_packets', 'rx_errors', 'rx_dropped', 'rx_over_errors', 'multicast'],
+ 'tx': ['tx_bytes', 'tx_packets', 'tx_errors', 'tx_dropped', 'tx_carrier_errors', 'collisions'],
+ }
+ tabs = []
+ for rtx in list(stats_dir):
+ tabs.append([f'{rtx.upper()}:', ] + stat_names[rtx])
+ tabs.append(['', ] + [stats[_] for _ in stats_dir[rtx]])
+
+ s = tabulate(
+ tabs,
+ stralign="right",
+ numalign="right",
+ tablefmt="plain"
+ )
+
+ p = ' '*indent
+ return f'{p}' + s.replace('\n', f'\n{p}')
@register('show')
def run_show_intf(ifnames, iftypes, vif, vrrp):
@@ -185,8 +210,12 @@ def run_show_intf(ifnames, iftypes, vif, vrrp):
if description:
print(f' Description: {description}')
+ stats = interface.operational.get_stats()
+ for k in list(stats):
+ stats[k] = get_counter_val(cache[k], stats[k])
+
print()
- print(interface.operational.formated_stats())
+ print(_format_stats(stats))
for ifname in ifnames:
if ifname not in handled and ifname.startswith('pppoe'):