From bbbd94f4dd468bda60664854a079a8c0c629c38b Mon Sep 17 00:00:00 2001 From: Mykola F <37578614+mykolaf@users.noreply.github.com> Date: Wed, 18 Nov 2020 19:33:19 +0200 Subject: [PATCH] [enable counters] provide initial rates parameters (#5048) * [enable counters] provide initial rates parameters Signed-off-by: Mykola Faryma * add descriptive comment Signed-off-by: Mykola Faryma Co-authored-by: Volodymyr Samotiy --- dockers/docker-orchagent/enable_counters.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/dockers/docker-orchagent/enable_counters.py b/dockers/docker-orchagent/enable_counters.py index 2067baefbf..b412517d36 100755 --- a/dockers/docker-orchagent/enable_counters.py +++ b/dockers/docker-orchagent/enable_counters.py @@ -1,9 +1,14 @@ #!/usr/bin/env python3 import time - import swsssdk +# ALPHA defines the size of the window over which we calculate the average value. ALPHA is 2/(N+1) where N is the interval(window size) +# In this case we configure the window to be 10s. This way if we have a huge 1s spike in traffic, +# the average rate value will show a curve descending from the spike to the usual rate over approximately 10s. +DEFAULT_SMOOTH_INTERVAL = '10' +DEFAULT_ALPHA = '0.18' + def enable_counter_group(db, name): info = {} @@ -11,6 +16,16 @@ def enable_counter_group(db, name): db.mod_entry("FLEX_COUNTER_TABLE", name, info) +def enable_rates(): + # set the default interval for rates + counters_db = swsssdk.SonicV2Connector() + counters_db.connect('COUNTERS_DB') + counters_db.set('COUNTERS_DB', 'RATES:PORT', 'PORT_SMOOTH_INTERVAL', DEFAULT_SMOOTH_INTERVAL) + counters_db.set('COUNTERS_DB', 'RATES:PORT', 'PORT_ALPHA', DEFAULT_ALPHA) + counters_db.set('COUNTERS_DB', 'RATES:RIF', 'RIF_SMOOTH_INTERVAL', DEFAULT_SMOOTH_INTERVAL) + counters_db.set('COUNTERS_DB', 'RATES:RIF', 'RIF_ALPHA', DEFAULT_ALPHA) + + def enable_counters(): db = swsssdk.ConfigDBConnector() db.connect() @@ -22,6 +37,7 @@ def enable_counters(): enable_counter_group(db, 'QUEUE_WATERMARK') enable_counter_group(db, 'BUFFER_POOL_WATERMARK') enable_counter_group(db, 'PORT_BUFFER_DROP') + enable_rates() def get_uptime(): @@ -43,3 +59,4 @@ def main(): if __name__ == '__main__': main() +