Skip to content
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]: Read counters from database #19

Merged
merged 4 commits into from
Mar 29, 2017

Conversation

sihuihan88
Copy link
Contributor

Signed-off-by: Sihui Han sihan@microsoft.com

Signed-off-by: Sihui Han <sihan@microsoft.com>
scripts/portstat Outdated
def natural_sort(l):
convert = lambda text: int(text) if text.isdigit() else text.lower()
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ]
return sorted(l, key = alphanum_key)
Copy link
Contributor

@jleveque jleveque Mar 23, 2017

Choose a reason for hiding this comment

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

This is not very portable (I know because I wrote pretty much the same function in minigraph_facts.py). Might be better to install the natsort library as a dependency and use natsort.natsorted(), which is what I wound up doing instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to make it portable?
All we're sorting here is name of the interface which is in our case most time 'EthernetX'

Copy link
Contributor

@jleveque jleveque Mar 23, 2017

Choose a reason for hiding this comment

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

If we move up to Python 3 we might have issues. Also, the need for this functionality has arisen twice in the past month, thus it's likely to come up again. It's better to use a popular library than write duplicate code where needed.

Copy link
Contributor

@pavel-shirshov pavel-shirshov Mar 24, 2017

Choose a reason for hiding this comment

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

I don't like natsort library because:

  1. debian has outdated version of the library
  2. this library break an api

Also I think this function is so small so it's ok to have it in our code.

Copy link
Contributor

@jleveque jleveque Mar 24, 2017

Choose a reason for hiding this comment

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

@pavel-shirshov: I agree with 1. Could you expound on 2? Which API does it break?

Copy link
Contributor

Choose a reason for hiding this comment

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

natsort() in debian repo vs natsorted() in pypi.
See:
sonic-net/sonic-mgmt@957220e

Copy link
Contributor

@jleveque jleveque Mar 24, 2017

Choose a reason for hiding this comment

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

Gotcha. You're just referring the change in their own API. I think we had a very outdated version on our internal machine. It was so old the package itself even had a different name, naturalsort version 1.5.1, I believe. Even though it was called naturalsort, the module you imported was still called natsort which caused the conflict.

It seems like the latest version of natsort in the Debian repos is 3.5.1, which has the newer natsorted() API. It is still a bit outdated, however, as the latest version is 5.0.2, but I don't think we need to worry about the API change unless we accidentally install naturalsort.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the lib keeps changing API name, I am not sure whether it's a good idea to use it in our project.

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can tell, the API changed only once, when the package changed its name from naturalsort to natsort.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. Great I will use this lib then :)

CNT_DB = 2
COUNTER_PORT_NAME_MAP = "COUNTERS_PORT_NAME_MAP"

class sonic_py(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

This module name should be more descriptive. Maybe sonic_db.py?

Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/Azure/sonic-py-swsssdk - Python utility library for sonic/switch state service database access. Should we use them?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, Pavel. I was unaware that library existed. if it works, we should use it and not reinvent the wheel. Sihui, please take a look.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use that. It seems that the library is a little bit out of date, but we could still pick it up. For the other tool, the 'aclshow' in #18, I think we also need to use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for all the info. I will take a look and try to use this library

@@ -34,6 +34,7 @@
install_requires=[
'click',
'click-default-group',
'natsort',
'tabulate'
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably list sswsdk as a dependency here, also.

Copy link
Contributor

@jleveque jleveque Mar 27, 2017

Choose a reason for hiding this comment

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

Unfortunately, we can't list sswsdk as a dependency here. Since we compile sonic-utilities into a .deb package, stdeb converts all Python dependencies here into Debian dependencies, thus it looks for installed .deb packages named "python-<python_package_name>". However, since we install sswsdk directly as a Python Wheel, it does not show up as an installed .deb package, so the sonic-utilities install will fail. We may want to consider unifying our package creation process.

scripts/portstat Outdated
'SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS': 0,
'SAI_PORT_STAT_IF_IN_ERRORS': 1,
'SAI_PORT_STAT_IF_IN_DISCARDS': 2,
'SAI_PORT_STAT_ETHER_TX_OVERSIZE_PKTS': 3,
Copy link
Contributor

Choose a reason for hiding this comment

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

-> RX_OVERSIZE_PKTS

scripts/portstat Outdated
'SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS': 4,
'SAI_PORT_STAT_IF_OUT_ERRORS': 5,
'SAI_PORT_STAT_IF_OUT_DISCARDS': 6,
'SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS': 7,
Copy link
Contributor

Choose a reason for hiding this comment

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

-> TX_OVERSIZE_PKTS

fields = [0,0,0,0,0,0,0,0,0,0]
for counter_name, pos in counter_bucket_dict.iteritems():
full_table_id = COUNTER_TABLE_PREFIX + table_id
fields[pos] += int(self.db.get(self.db.COUNTERS_DB, full_table_id, counter_name))
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use hmget to get all interested fields for a key in one shot?

https://redis.io/commands/hmget

Copy link
Contributor Author

@sihuihan88 sihuihan88 Mar 28, 2017

Choose a reason for hiding this comment

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

We are using swssdk lib which hasn't implemented the method similar as hmget in redis-py. If we want to use the hmget, we need to update the swssdk first.

scripts/portstat Outdated
'SAI_PORT_STAT_IF_OUT_UCAST_PKTS': 4,
'SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS': 4,
'SAI_PORT_STAT_IF_OUT_ERRORS': 5,
'SAI_PORT_STAT_IF_OUT_DISCARDS': 6,
Copy link
Contributor

Choose a reason for hiding this comment

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

do we know if OUT_DISCARDS map to all the counters we used to get from bshell? TDBGC0, 3, 5, 8 and the UCQ_DROP_PKT counters?

Signed-off-by: Sihui Han <sihan@microsoft.com>
scripts/portstat Outdated

class Portstat(object):
def __init__(self):
self.db = sswsdk.SonicV2Connector()
Copy link
Contributor

Choose a reason for hiding this comment

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

sonic-net/sonic-py-swsssdk#4 once this is merged. be sure to update all the related names.

Signed-off-by: Sihui Han <sihan@microsoft.com>
@stcheng stcheng merged commit 5c59ec6 into sonic-net:master Mar 29, 2017
@sihuihan88 sihuihan88 deleted the database branch March 30, 2017 21:16
praveen-li pushed a commit to praveen-li/sonic-utilities that referenced this pull request Mar 23, 2020
* [config_mgmt.py]: Redirect logs to syslog.

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com

* [config_mgmt.py]: Call openlog and closelog one time.

Changes:
1.) Call openlog and closelog one time.
2.) call syslog directly.
3.) mask loglevel based on debug argument to class.
4.) Class destructor to call closelog.

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com

* [config_mgmt.py]: Fixing minor typo.

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com

* [config_mgmt.py]: Call openlog and closelog each time from a wrapper function.

It is mandotary to call openlog and closelog eachtime while using syslog library.
Since it is one class Instance shared among all python applications.

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
vdahiya12 pushed a commit to vdahiya12/sonic-utilities that referenced this pull request Jul 23, 2021
mihirpat1 pushed a commit to mihirpat1/sonic-utilities that referenced this pull request Sep 15, 2023
* Changes of SONiC new platform API based on latest design

* Moved get_change_event from DeviceBase to ChassisBase and ModuleBase

* chassis_base.py : added get_change_event
device_base.py : fixed typo
fan_base.py : defined DEVICE_TYPE
module_base.py : defined DEVICE_TYPE, fixed typo
psu_base.py : defined DEVICE_TYPE
sfp_base.py : defined DEVICE_TYPE, fixed typo, modified descriptions of set_power_override
thermal_base.py : defined DEVICE_TYPE

* module_base.py : modified get_change_event to return devices in nested dict

* Added dom related status support for SFP, including temperature, voltage, TX bias, TX power and RX power

* 1. Per channel return for TX bias, TX power and RX power in sfp_base.py.
2. Support system EEPROM and serial number in chassis_base.py.

* 1. Added SYS EEPROM functions to module_base.py.  2. Fixed typos.  3. Merge get_watchdog to return self._watchdog in chassis_base

* 1. Fixed various typos.  2. Changed get_ampere to get_current, get_watt to get_power in psu_base.py

* Changed get_system_eeprom return to use type code defined in ONIE TlvInfo EEPROM as the keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants