Skip to content

Commit c4c6808

Browse files
authored
suppport multi asic for show queue counter (sonic-net#2439)
Added option -n for both "show queue counter" and "queuestat", using multi_asic module in queuestat to query database of specified namespace. Removed function get_queue_port() to decrease the times of connecting database.
1 parent 1b21201 commit c4c6808

File tree

4 files changed

+756
-69
lines changed

4 files changed

+756
-69
lines changed

scripts/queuestat

+18-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import sys
1515
from collections import namedtuple, OrderedDict
1616
from natsort import natsorted
1717
from tabulate import tabulate
18+
from sonic_py_common import multi_asic
1819

1920
# mock the redis for unit test purposes #
2021
try:
@@ -24,12 +25,17 @@ try:
2425
sys.path.insert(0, modules_path)
2526
sys.path.insert(0, tests_path)
2627
import mock_tables.dbconnector # lgtm [py/unused-import]
28+
if os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] == "multi_asic":
29+
import mock_tables.mock_multi_asic
30+
mock_tables.dbconnector.load_namespace_config()
2731

2832
except KeyError:
2933
pass
3034

3135
from swsscommon.swsscommon import SonicV2Connector
3236
from utilities_common.cli import UserCache
37+
from utilities_common import constants
38+
import utilities_common.multi_asic as multi_asic_util
3339

3440
QueueStats = namedtuple("QueueStats", "queueindex, queuetype, totalpacket, totalbytes, droppacket, dropbytes")
3541
header = ['Port', 'TxQ', 'Counter/pkts', 'Counter/bytes', 'Drop/pkts', 'Drop/bytes']
@@ -85,9 +91,15 @@ def build_json(port, cnstat):
8591

8692

8793
class Queuestat(object):
88-
def __init__(self, voq=False):
89-
self.db = SonicV2Connector(use_unix_socket_path=False)
90-
self.db.connect(self.db.COUNTERS_DB)
94+
def __init__(self, namespace, voq=False):
95+
self.db = None
96+
self.multi_asic = multi_asic_util.MultiAsic(constants.DISPLAY_ALL, namespace)
97+
if namespace is not None:
98+
for ns in self.multi_asic.get_ns_list_based_on_options():
99+
self.db = multi_asic.connect_to_all_dbs_for_ns(ns)
100+
else:
101+
self.db = SonicV2Connector(use_unix_socket_path=False)
102+
self.db.connect(self.db.COUNTERS_DB)
91103
self.voq = voq
92104

93105
def get_queue_port(table_id):
@@ -345,12 +357,14 @@ Examples:
345357
parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0')
346358
parser.add_argument('-j', '--json_opt', action='store_true', help='Print in JSON format')
347359
parser.add_argument('-V', '--voq', action='store_true', help='display voq stats')
360+
parser.add_argument('-n','--namespace', default=None, help='Display queue counters for specific namespace')
348361
args = parser.parse_args()
349362

350363
save_fresh_stats = args.clear
351364
delete_stats = args.delete
352365
voq = args.voq
353366
json_opt = args.json_opt
367+
namespace = args.namespace
354368

355369
port_to_show_stats = args.port
356370

@@ -362,7 +376,7 @@ Examples:
362376
if delete_stats:
363377
cache.remove()
364378

365-
queuestat = Queuestat( voq )
379+
queuestat = Queuestat( namespace, voq )
366380

367381
if save_fresh_stats:
368382
queuestat.save_fresh_stats()

show/main.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -704,10 +704,11 @@ def queue():
704704
# 'counters' subcommand ("show queue counters")
705705
@queue.command()
706706
@click.argument('interfacename', required=False)
707+
@multi_asic_util.multi_asic_click_options
707708
@click.option('--verbose', is_flag=True, help="Enable verbose output")
708709
@click.option('--json', is_flag=True, help="JSON output")
709710
@click.option('--voq', is_flag=True, help="VOQ counters")
710-
def counters(interfacename, verbose, json, voq):
711+
def counters(interfacename, namespace, display, verbose, json, voq):
711712
"""Show queue counters"""
712713

713714
cmd = "queuestat"
@@ -719,6 +720,9 @@ def counters(interfacename, verbose, json, voq):
719720
if interfacename is not None:
720721
cmd += " -p {}".format(interfacename)
721722

723+
if namespace is not None:
724+
cmd += " -n {}".format(namespace)
725+
722726
if json:
723727
cmd += " -j"
724728

0 commit comments

Comments
 (0)