From cfb5cca3203deab1920a764fcea99a150ecb8542 Mon Sep 17 00:00:00 2001 From: Mykola Faryma Date: Mon, 27 Jul 2020 17:56:21 +0300 Subject: [PATCH 1/2] [enable counters] provide initial rates parameters Signed-off-by: Mykola Faryma --- dockers/docker-orchagent/enable_counters.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/dockers/docker-orchagent/enable_counters.py b/dockers/docker-orchagent/enable_counters.py index 9ce7a0f8d8b4..4f986fa3c43d 100755 --- a/dockers/docker-orchagent/enable_counters.py +++ b/dockers/docker-orchagent/enable_counters.py @@ -3,11 +3,24 @@ import swsssdk import time +DEFAULT_SMOOTH_INTERVAL = '10' +DEFAULT_ALPHA = '0.18' + def enable_counter_group(db, name): info = {} info['FLEX_COUNTER_STATUS'] = 'enable' db.mod_entry("FLEX_COUNTER_TABLE", name, info) +def enable_rates(): + # set the default interval for rates (N) as 10s, alpha is 2/(N+1) + 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() @@ -18,6 +31,7 @@ def enable_counters(): enable_counter_group(db, 'PG_WATERMARK') enable_counter_group(db, 'QUEUE_WATERMARK') enable_counter_group(db, 'BUFFER_POOL_WATERMARK') + enable_rates() def get_uptime(): with open('/proc/uptime') as fp: @@ -36,3 +50,4 @@ def main(): if __name__ == '__main__': main() + From b5eafead3e47a31e4f0923fd518077799a526440 Mon Sep 17 00:00:00 2001 From: Mykola Faryma Date: Wed, 12 Aug 2020 13:23:23 +0300 Subject: [PATCH 2/2] add descriptive comment Signed-off-by: Mykola Faryma --- dockers/docker-orchagent/enable_counters.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dockers/docker-orchagent/enable_counters.py b/dockers/docker-orchagent/enable_counters.py index 4f986fa3c43d..187f3a8e9d72 100755 --- a/dockers/docker-orchagent/enable_counters.py +++ b/dockers/docker-orchagent/enable_counters.py @@ -3,6 +3,9 @@ import swsssdk import time +# 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' @@ -12,7 +15,7 @@ def enable_counter_group(db, name): db.mod_entry("FLEX_COUNTER_TABLE", name, info) def enable_rates(): - # set the default interval for rates (N) as 10s, alpha is 2/(N+1) + # 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)