diff --git a/scripts/portstat b/scripts/portstat index 002a6f43b8..69ab0f3b6d 100755 --- a/scripts/portstat +++ b/scripts/portstat @@ -38,8 +38,6 @@ from utilities_common.intf_filter import parse_interface_in_filter import utilities_common.multi_asic as multi_asic_util from utilities_common.netstat import ns_diff, table_as_json, format_brate, format_prate, format_util -PORT_RATE = 40 - """ The order and count of statistics mentioned below needs to be in sync with the values in portstat script So, any fields added/deleted in here should be reflected in portstat script also @@ -215,8 +213,8 @@ class Portstat(object): self.db = multi_asic.connect_to_all_dbs_for_ns(ns) speed = self.db.get(self.db.APPL_DB, full_table_id, PORT_SPEED_FIELD) if speed is not None: - return int(speed)//1000 - return PORT_RATE + return int(speed) + return STATUS_NA def get_port_state(self, port_name): """ diff --git a/tests/portstat_test.py b/tests/portstat_test.py index d79e421507..36de04cd40 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -15,22 +15,22 @@ IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR --------- ------- ------- ------------ --------- -------- -------- -------- ------- ----------- --------- -------- -------- -------- Ethernet0 D 8 0.00 B/s 0.00% 10 100 N/A 10 0.00 B/s 0.00% N/A N/A N/A -Ethernet4 N/A 4 200.00 KB/s 0.00% 0 1000 N/A 40 200.05 KB/s 0.00% N/A N/A N/A -Ethernet8 N/A 6 1318.36 KB/s 0.03% 100 10 N/A 60 12.75 MB/s 0.25% N/A N/A N/A +Ethernet4 N/A 4 200.00 KB/s N/A 0 1000 N/A 40 200.05 KB/s N/A N/A N/A N/A +Ethernet8 N/A 6 1318.36 KB/s N/A 100 10 N/A 60 12.75 MB/s N/A N/A N/A N/A """ intf_counters_ethernet4 = """\ IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR --------- ------- ------- ----------- --------- -------- -------- -------- ------- ----------- --------- -------- -------- -------- -Ethernet4 N/A 4 200.00 KB/s 0.00% 0 1000 N/A 40 200.05 KB/s 0.00% N/A N/A N/A +Ethernet4 N/A 4 200.00 KB/s N/A 0 1000 N/A 40 200.05 KB/s N/A N/A N/A N/A """ intf_counters_all = """\ IFACE STATE RX_OK RX_BPS RX_PPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_PPS TX_UTIL TX_ERR TX_DRP TX_OVR --------- ------- ------- ------------ --------- --------- -------- -------- -------- ------- ----------- --------- --------- -------- -------- -------- Ethernet0 D 8 0.00 B/s 0.00/s 0.00% 10 100 N/A 10 0.00 B/s 0.00/s 0.00% N/A N/A N/A -Ethernet4 N/A 4 200.00 KB/s 200.00/s 0.00% 0 1000 N/A 40 200.05 KB/s 201.00/s 0.00% N/A N/A N/A -Ethernet8 N/A 6 1318.36 KB/s 9000.00/s 0.03% 100 10 N/A 60 12.75 MB/s 9000.00/s 0.25% N/A N/A N/A +Ethernet4 N/A 4 200.00 KB/s 200.00/s N/A 0 1000 N/A 40 200.05 KB/s 201.00/s N/A N/A N/A N/A +Ethernet8 N/A 6 1318.36 KB/s 9000.00/s N/A 100 10 N/A 60 12.75 MB/s 9000.00/s N/A N/A N/A N/A """ intf_counters_period = """\ @@ -38,16 +38,16 @@ IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR --------- ------- ------- ------------ --------- -------- -------- -------- ------- ----------- --------- -------- -------- -------- Ethernet0 D 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A -Ethernet4 N/A 0 200.00 KB/s 0.00% 0 0 N/A 0 200.05 KB/s 0.00% N/A N/A N/A -Ethernet8 N/A 0 1318.36 KB/s 0.03% 0 0 N/A 0 12.75 MB/s 0.25% N/A N/A N/A +Ethernet4 N/A 0 200.00 KB/s N/A 0 0 N/A 0 200.05 KB/s N/A N/A N/A N/A +Ethernet8 N/A 0 1318.36 KB/s N/A 0 0 N/A 0 12.75 MB/s N/A N/A N/A N/A """ intf_counter_after_clear = """\ IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR --------- ------- ------- ------------ --------- -------- -------- -------- ------- ----------- --------- -------- -------- -------- Ethernet0 D 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A -Ethernet4 N/A 0 200.00 KB/s 0.00% 0 0 N/A 0 200.05 KB/s 0.00% N/A N/A N/A -Ethernet8 N/A 0 1318.36 KB/s 0.03% 0 0 N/A 0 12.75 MB/s 0.25% N/A N/A N/A""" +Ethernet4 N/A 0 200.00 KB/s N/A 0 0 N/A 0 200.05 KB/s N/A N/A N/A N/A +Ethernet8 N/A 0 1318.36 KB/s N/A 0 0 N/A 0 12.75 MB/s N/A N/A N/A N/A""" clear_counter = """\ Cleared counters""" diff --git a/tests/rates_test.py b/tests/rates_test.py index 0a0b109fd2..873a45b9d0 100644 --- a/tests/rates_test.py +++ b/tests/rates_test.py @@ -15,8 +15,8 @@ IFACE STATE RX_OK RX_BPS RX_PPS RX_UTIL TX_OK TX_BPS TX_PPS TX_UTIL --------- ------- ------- ------------ --------- --------- ------- ----------- --------- --------- Ethernet0 D 8 0.00 B/s 0.00/s 0.00% 10 0.00 B/s 0.00/s 0.00% -Ethernet4 N/A 4 200.00 KB/s 200.00/s 0.00% 40 200.05 KB/s 201.00/s 0.00% -Ethernet8 N/A 6 1318.36 KB/s 9000.00/s 0.03% 60 12.75 MB/s 9000.00/s 0.25% +Ethernet4 N/A 4 200.00 KB/s 200.00/s N/A 40 200.05 KB/s 201.00/s N/A +Ethernet8 N/A 6 1318.36 KB/s 9000.00/s N/A 60 12.75 MB/s 9000.00/s N/A """ diff --git a/utilities_common/netstat.py b/utilities_common/netstat.py index e1863229c9..31168d5709 100755 --- a/utilities_common/netstat.py +++ b/utilities_common/netstat.py @@ -82,14 +82,14 @@ def format_prate(rate): #TODO what does it mean /s maybe p/s packets per seconds return "{:.2f}".format(float(rate))+'/s' -def format_util(brate, port_rate=PORT_RATE): +def format_util(brate, port_rate): """ Calculate the util. """ - if brate == STATUS_NA: + if brate == STATUS_NA or port_rate == STATUS_NA: return STATUS_NA else: - util = brate/(float(port_rate)*1024*1024*1024/8.0)*100 + util = brate/(float(port_rate)*1024*1024/8.0)*100 return "{:.2f}%".format(util) def table_as_json(table, header):