-
Notifications
You must be signed in to change notification settings - Fork 666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[portstat, intfstat] update rates and utilization #817
Changes from all commits
dec5cd8
47e355c
93e2cd0
d9adb96
3b46b03
0f98cc9
66cf477
3344cbe
c791d35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,12 +28,12 @@ except KeyError: | |
from collections import namedtuple, OrderedDict | ||
from natsort import natsorted | ||
from tabulate import tabulate | ||
from utilities_common.netstat import ns_diff, ns_brate, ns_prate, table_as_json, STATUS_NA | ||
from utilities_common.netstat import ns_diff, ns_brate, ns_prate, table_as_json, STATUS_NA, format_brate, format_prate, format_util | ||
from swsscommon.swsscommon import SonicV2Connector | ||
|
||
|
||
NStats = namedtuple("NStats", "rx_b_ok, rx_p_ok, tx_b_ok, tx_p_ok,\ | ||
rx_b_err, rx_p_err, tx_b_err, tx_p_err,") | ||
nstat_fields = ("rx_b_ok", "rx_p_ok", "tx_b_ok", "tx_p_ok",\ | ||
"rx_b_err", "rx_p_err", "tx_b_err", "tx_p_err") | ||
NStats = namedtuple("NStats", nstat_fields) | ||
|
||
header = ['IFACE', 'RX_OK', 'RX_BPS', 'RX_PPS', 'RX_ERR', | ||
'TX_OK', 'TX_BPS', 'TX_PPS', 'TX_ERR'] | ||
|
@@ -76,7 +76,7 @@ class Intfstat(object): | |
""" | ||
Get the counters from specific table. | ||
""" | ||
fields = [STATUS_NA] * (len(header) - 1) | ||
fields = [STATUS_NA] * len(nstat_fields) | ||
for pos, counter_name in enumerate(counter_names): | ||
full_table_id = COUNTER_TABLE_PREFIX + table_id | ||
counter_data = self.db.get(self.db.COUNTERS_DB, full_table_id, counter_name) | ||
|
@@ -127,6 +127,24 @@ class Intfstat(object): | |
else: | ||
return STATUS_NA | ||
|
||
def get_intf_speed(self, port_name): | ||
""" | ||
Get the Intf speed | ||
""" | ||
full_table_id = PORT_STATUS_TABLE_PREFIX + port_name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PORT_STATUS_TABLE_PREFIX doesn't seem to be defined anywhere. Missing code? |
||
admin_state = self.db.get(self.db.APPL_DB, full_table_id, PORT_ADMIN_STATUS_FIELD) | ||
oper_state = self.db.get(self.db.APPL_DB, full_table_id, PORT_OPER_STATUS_FIELD) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PORT_OPER_STATUS_FIELD doesn't seem to be defined anywhere. Missing code? |
||
if admin_state is None or oper_state is None: | ||
return STATUS_NA | ||
elif admin_state.upper() == PORT_STATUS_VALUE_DOWN: | ||
return PORT_STATE_DISABLED | ||
elif admin_state.upper() == PORT_STATUS_VALUE_UP and oper_state.upper() == PORT_STATUS_VALUE_UP: | ||
return PORT_STATE_UP | ||
elif admin_state.upper() == PORT_STATUS_VALUE_UP and oper_state.upper() == PORT_STATUS_VALUE_DOWN: | ||
return PORT_STATE_DOWN | ||
else: | ||
Comment on lines
+137
to
+145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check all the variables used there. They don't seem to be defined. |
||
return STATUS_NA | ||
|
||
def cnstat_print(self, cnstat_dict, use_json): | ||
""" | ||
Print the cnstat. | ||
|
@@ -173,15 +191,21 @@ class Intfstat(object): | |
ns_prate(cntr.tx_p_ok, old_cntr.tx_p_ok, time_gap), | ||
ns_diff(cntr.tx_p_err, old_cntr.tx_p_err))) | ||
else: | ||
table.append((key, | ||
cntr.rx_p_ok, | ||
STATUS_NA, | ||
STATUS_NA, | ||
cntr.rx_p_err, | ||
cntr.tx_p_ok, | ||
STATUS_NA, | ||
STATUS_NA, | ||
cntr.tx_p_err)) | ||
old_cntr = NStats._make([0] * len(nstat_fields)) | ||
|
||
rates = ratestat_dict.get(key, RateStats._make([STATUS_NA]*len(ratestat_fields))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think ratestat_dict is defined anywhere else in the file. Is there a missing piece of code? |
||
|
||
table.append((key, | ||
ns_diff(cntr.rx_p_ok, old_cntr.rx_p_ok), | ||
format_brate(rates.rx_bps), | ||
format_prate(rates.rx_pps), | ||
format_util(rates.rx_bps, speed), | ||
ns_diff(cntr.rx_p_err, old_cntr.rx_p_err), | ||
ns_diff(cntr.tx_p_ok, old_cntr.tx_p_ok), | ||
format_brate(rates.tx_bps), | ||
format_prate(rates.tx_pps), | ||
format_util(rates.tx_bps, speed), | ||
ns_diff(cntr.tx_p_err, old_cntr.tx_p_err))) | ||
if use_json: | ||
print(table_as_json(table, header)) | ||
else: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API is not called anywhere. Why is this API needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also check why get_intf_state is needed. I don't see it called anywhere