Skip to content

Commit

Permalink
[enable_counters.py] Convert to Python 3 (#5789)
Browse files Browse the repository at this point in the history
**- Why I did it**

As part of moving all SONiC code from Python 2 (no longer supported) to Python 3

**- How I did it**

- Convert enable_counters.py script to Python 3
- Reorganize imports per PEP8 standard
- Two blank lines precede functions per PEP8 standard
  • Loading branch information
jleveque committed Nov 6, 2020
1 parent cea364a commit 5129233
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions dockers/docker-orchagent/enable_counters.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import swsssdk
import time

import swsssdk


def enable_counter_group(db, name):
info = {}
info['FLEX_COUNTER_STATUS'] = 'enable'
db.mod_entry("FLEX_COUNTER_TABLE", name, info)


def enable_counters():
db = swsssdk.ConfigDBConnector()
db.connect()
Expand All @@ -20,10 +23,12 @@ def enable_counters():
enable_counter_group(db, 'BUFFER_POOL_WATERMARK')
enable_counter_group(db, 'PORT_BUFFER_DROP')


def get_uptime():
with open('/proc/uptime') as fp:
return float(fp.read().split(' ')[0])


def main():
# If the switch was just started (uptime less than 5 minutes),
# wait for 3 minutes and enable counters
Expand All @@ -35,5 +40,6 @@ def main():
time.sleep(60)
enable_counters()


if __name__ == '__main__':
main()

0 comments on commit 5129233

Please sign in to comment.