Skip to content

Commit

Permalink
[swss]: Start counter from swss container (#1875)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pavel-shirshov authored and lguohan committed Jul 26, 2018
1 parent 3c33737 commit 10b4bbc
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 22 deletions.
1 change: 1 addition & 0 deletions dockers/docker-orchagent/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y
RUN rm -rf /debs

COPY ["files/arp_update", "/usr/bin"]
COPY ["enable_counters.py", "/usr/bin"]
COPY ["start.sh", "orchagent.sh", "swssconfig.sh", "/usr/bin/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]

Expand Down
34 changes: 34 additions & 0 deletions dockers/docker-orchagent/enable_counters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python

import swsssdk
import time

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, 'QUEUE')
enable_counter_group(db, 'PFCWD')

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()
2 changes: 2 additions & 0 deletions dockers/docker-orchagent/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ supervisorctl start intfmgrd

supervisorctl start buffermgrd

supervisorctl start enable_counters

# Start arp_update when VLAN exists
VLAN=`sonic-cfggen -d -v 'VLAN.keys() | join(" ") if VLAN'`
if [ "$VLAN" != "" ]; then
Expand Down
8 changes: 8 additions & 0 deletions dockers/docker-orchagent/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,11 @@ autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog

[program:enable_counters]
command=/usr/bin/enable_counters.py
priority=11
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog
8 changes: 0 additions & 8 deletions files/build_templates/enable_counters.service

This file was deleted.

9 changes: 0 additions & 9 deletions files/build_templates/enable_counters.timer

This file was deleted.

4 changes: 2 additions & 2 deletions files/build_templates/snmp.service.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=SNMP container
Requires=updategraph.service swss.service enable_counters.service
After=updategraph.service swss.service enable_counters.service
Requires=updategraph.service swss.service
After=updategraph.service swss.service

[Service]
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
Expand Down
3 changes: 0 additions & 3 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,7 @@ sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys

# Copy systemd timer configuration
# It implements delayed start of services
sudo cp $BUILD_TEMPLATES/enable_counters.timer $FILESYSTEM_ROOT/etc/systemd/system/
sudo cp $BUILD_TEMPLATES/enable_counters.service $FILESYSTEM_ROOT/etc/systemd/system/
sudo cp $BUILD_TEMPLATES/snmp.timer $FILESYSTEM_ROOT/etc/systemd/system/
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable enable_counters.timer
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable snmp.timer

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

0 comments on commit 10b4bbc

Please sign in to comment.