Skip to content

Commit

Permalink
[pfcwd]: Refine 'show stats' output (sonic-net#170)
Browse files Browse the repository at this point in the history
Group columns in OK/DROP pairs
Add option to show empty lines now hidden by default

Signed-off-by: marian-pritsak <[email protected]>
  • Loading branch information
marian-pritsak authored and lguohan committed Dec 14, 2017
1 parent 0fdd9f9 commit 8677d5f
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions pfcwd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@
from natsort import natsorted

STATS_DESCRIPTION = [
('STORM DETECTED CNT', 'PFC_WD_QUEUE_STATS_DEADLOCK_DETECTED'),
('STORM RESTORED CNT', 'PFC_WD_QUEUE_STATS_DEADLOCK_RESTORED'),
('TX PACKETS', 'PFC_WD_QUEUE_STATS_TX_PACKETS'),
('RX PACKETS', 'PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS'),
('TX PACKETS DROP', 'PFC_WD_QUEUE_STATS_RX_PACKETS'),
('RX PACKETS DROP', 'PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST'),
('TX PACKETS LAST', 'PFC_WD_QUEUE_STATS_TX_PACKETS_LAST'),
('RX PACKETS LAST', 'PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS_LAST'),
('TX PACKETS LAST DROP', 'PFC_WD_QUEUE_STATS_RX_PACKETS_LAST'),
('RX PACKETS LAST DROP', 'PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST')
('STORM DETECTED/RESTORED', 'PFC_WD_QUEUE_STATS_DEADLOCK_DETECTED', 'PFC_WD_QUEUE_STATS_DEADLOCK_RESTORED'),
('TX OK/DROP', 'PFC_WD_QUEUE_STATS_TX_PACKETS', 'PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS'),
('RX OK/DROP', 'PFC_WD_QUEUE_STATS_RX_PACKETS', 'PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS'),
('TX LAST OK/DROP', 'PFC_WD_QUEUE_STATS_TX_PACKETS_LAST', 'PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS_LAST'),
('RX LAST OK/DROP', 'PFC_WD_QUEUE_STATS_RX_PACKETS_LAST', 'PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST'),
]

CONFIG_DESCRIPTION = [
Expand Down Expand Up @@ -47,8 +42,9 @@ def show():

# Show stats
@show.command()
@click.option('-e', '--empty', is_flag = True)
@click.argument('queues', nargs = -1)
def stats(queues):
def stats(empty, queues):
""" Show PFC Watchdog stats per queue """
db = swsssdk.SonicV2Connector(host='127.0.0.1')
db.connect(db.COUNTERS_DB)
Expand All @@ -64,9 +60,10 @@ def stats(queues):
if stats is None:
continue
for stat in STATS_DESCRIPTION:
line = stats.get(stat[1], '0')
line = stats.get(stat[1], '0') + '/' + stats.get(stat[2], '0')
stats_list.append(line)
table.append([queue] + stats_list)
if stats_list != ['0/0'] * len(STATS_DESCRIPTION) or empty:
table.append([queue] + stats_list)

click.echo(tabulate(table, STATS_HEADER, stralign='right', numalign='right', tablefmt='simple'))

Expand Down

0 comments on commit 8677d5f

Please sign in to comment.