Skip to content
26 changes: 26 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,32 @@ def vrf(vrf_name):
body.append(["", intf])
click.echo(tabulate(body, header))

#
# 'events' command ("show event-counters")
#

@cli.command()
def event_counters():
"""Show events counter"""
# dump keys as formatted
counters_db = SonicV2Connector(host='127.0.0.1')
counters_db.connect(counters_db.COUNTERS_DB, retry_on=False)

header = ['name', 'count']
keys = counters_db.keys(counters_db.COUNTERS_DB, 'COUNTERS_EVENTS*')
table = []

for key in natsorted(keys):
key_list = key.split(':')
data_dict = counters_db.get_all(counters_db.COUNTERS_DB, key)
table.append((key_list[1], data_dict["value"]))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if key_list will ever be empty but maybe add sanity check that we are not accessing empty array

Copy link
Copy Markdown
Owner Author

@renukamanavalan renukamanavalan Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never.
< table name >:< keyname >

True for every redis entry


if table:
click.echo(tabulate(table, header, tablefmt='simple', stralign='right'))
else:
click.echo('No data available in COUNTERS_EVENTS\n')


#
# 'arp' command ("show arp")
#
Expand Down