sonic-buildimage/dockers/docker-orchagent/enable_counters.py
Joe LeVeque 51292330e9
[enable_counters.py] Convert to Python 3 (#5789)
**- 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
2020-11-06 09:00:19 -08:00

46 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python3
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()
enable_counter_group(db, 'PORT')
enable_counter_group(db, 'RIF')
enable_counter_group(db, 'QUEUE')
enable_counter_group(db, 'PFCWD')
enable_counter_group(db, 'PG_WATERMARK')
enable_counter_group(db, 'QUEUE_WATERMARK')
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
# otherwise wait for 60 seconds and enable counters
uptime = get_uptime()
if uptime < 300:
time.sleep(180)
else:
time.sleep(60)
enable_counters()
if __name__ == '__main__':
main()