1
1
#!/usr/bin/env python3
2
2
3
3
import time
4
-
5
4
import swsssdk
6
5
6
+ # 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)
7
+ # In this case we configure the window to be 10s. This way if we have a huge 1s spike in traffic,
8
+ # the average rate value will show a curve descending from the spike to the usual rate over approximately 10s.
9
+ DEFAULT_SMOOTH_INTERVAL = '10'
10
+ DEFAULT_ALPHA = '0.18'
11
+
7
12
8
13
def enable_counter_group (db , name ):
9
14
info = {}
10
15
info ['FLEX_COUNTER_STATUS' ] = 'enable'
11
16
db .mod_entry ("FLEX_COUNTER_TABLE" , name , info )
12
17
13
18
19
+ def enable_rates ():
20
+ # set the default interval for rates
21
+ counters_db = swsssdk .SonicV2Connector ()
22
+ counters_db .connect ('COUNTERS_DB' )
23
+ counters_db .set ('COUNTERS_DB' , 'RATES:PORT' , 'PORT_SMOOTH_INTERVAL' , DEFAULT_SMOOTH_INTERVAL )
24
+ counters_db .set ('COUNTERS_DB' , 'RATES:PORT' , 'PORT_ALPHA' , DEFAULT_ALPHA )
25
+ counters_db .set ('COUNTERS_DB' , 'RATES:RIF' , 'RIF_SMOOTH_INTERVAL' , DEFAULT_SMOOTH_INTERVAL )
26
+ counters_db .set ('COUNTERS_DB' , 'RATES:RIF' , 'RIF_ALPHA' , DEFAULT_ALPHA )
27
+
28
+
14
29
def enable_counters ():
15
30
db = swsssdk .ConfigDBConnector ()
16
31
db .connect ()
@@ -22,6 +37,7 @@ def enable_counters():
22
37
enable_counter_group (db , 'QUEUE_WATERMARK' )
23
38
enable_counter_group (db , 'BUFFER_POOL_WATERMARK' )
24
39
enable_counter_group (db , 'PORT_BUFFER_DROP' )
40
+ enable_rates ()
25
41
26
42
27
43
def get_uptime ():
@@ -43,3 +59,4 @@ def main():
43
59
44
60
if __name__ == '__main__' :
45
61
main ()
62
+
0 commit comments