Skip to content

Commit 10b4bbc

Browse files
pavel-shirshovlguohan
authored andcommitted
[swss]: Start counter from swss container (#1875)
* sonic-quagga update. Don't spam with 'Vtysh connected from' message * Enable counters inside swss container. systemd is not flexible enough to follow our business rules
1 parent 3c33737 commit 10b4bbc

File tree

8 files changed

+47
-22
lines changed

8 files changed

+47
-22
lines changed

dockers/docker-orchagent/Dockerfile.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y
3030
RUN rm -rf /debs
3131

3232
COPY ["files/arp_update", "/usr/bin"]
33+
COPY ["enable_counters.py", "/usr/bin"]
3334
COPY ["start.sh", "orchagent.sh", "swssconfig.sh", "/usr/bin/"]
3435
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
3536

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python
2+
3+
import swsssdk
4+
import time
5+
6+
def enable_counter_group(db, name):
7+
info = {}
8+
info['FLEX_COUNTER_STATUS'] = 'enable'
9+
db.mod_entry("FLEX_COUNTER_TABLE", name, info)
10+
11+
def enable_counters():
12+
db = swsssdk.ConfigDBConnector()
13+
db.connect()
14+
enable_counter_group(db, 'PORT')
15+
enable_counter_group(db, 'QUEUE')
16+
enable_counter_group(db, 'PFCWD')
17+
18+
def get_uptime():
19+
with open('/proc/uptime') as fp:
20+
return float(fp.read().split(' ')[0])
21+
22+
def main():
23+
# If the switch was just started (uptime less than 5 minutes),
24+
# wait for 3 minutes and enable counters
25+
# otherwise wait for 60 seconds and enable counters
26+
uptime = get_uptime()
27+
if uptime < 300:
28+
time.sleep(180)
29+
else:
30+
time.sleep(60)
31+
enable_counters()
32+
33+
if __name__ == '__main__':
34+
main()

dockers/docker-orchagent/start.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ supervisorctl start intfmgrd
2828

2929
supervisorctl start buffermgrd
3030

31+
supervisorctl start enable_counters
32+
3133
# Start arp_update when VLAN exists
3234
VLAN=`sonic-cfggen -d -v 'VLAN.keys() | join(" ") if VLAN'`
3335
if [ "$VLAN" != "" ]; then

dockers/docker-orchagent/supervisord.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,11 @@ autostart=false
9191
autorestart=false
9292
stdout_logfile=syslog
9393
stderr_logfile=syslog
94+
95+
[program:enable_counters]
96+
command=/usr/bin/enable_counters.py
97+
priority=11
98+
autostart=false
99+
autorestart=false
100+
stdout_logfile=syslog
101+
stderr_logfile=syslog

files/build_templates/enable_counters.service

Lines changed: 0 additions & 8 deletions
This file was deleted.

files/build_templates/enable_counters.timer

Lines changed: 0 additions & 9 deletions
This file was deleted.

files/build_templates/snmp.service.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[Unit]
22
Description=SNMP container
3-
Requires=updategraph.service swss.service enable_counters.service
4-
After=updategraph.service swss.service enable_counters.service
3+
Requires=updategraph.service swss.service
4+
After=updategraph.service swss.service
55

66
[Service]
77
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start

files/build_templates/sonic_debian_extension.j2

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys
285285

286286
# Copy systemd timer configuration
287287
# It implements delayed start of services
288-
sudo cp $BUILD_TEMPLATES/enable_counters.timer $FILESYSTEM_ROOT/etc/systemd/system/
289-
sudo cp $BUILD_TEMPLATES/enable_counters.service $FILESYSTEM_ROOT/etc/systemd/system/
290288
sudo cp $BUILD_TEMPLATES/snmp.timer $FILESYSTEM_ROOT/etc/systemd/system/
291-
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable enable_counters.timer
292289
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable snmp.timer
293290

294291
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get remove -y python-dev

0 commit comments

Comments
 (0)