[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
This commit is contained in:
pavel-shirshov 2018-07-26 13:39:08 -07:00 committed by lguohan
parent 3c33737d58
commit 10b4bbcae8
8 changed files with 47 additions and 22 deletions

View File

@ -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/"]

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -1,8 +0,0 @@
[Unit]
Description=Enable SONiC counters
PartOf=swss.service
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'sleep 60 ; /usr/bin/counterpoll queue enable ; /usr/bin/counterpoll port enable ; /usr/bin/pfcwd counter_poll enable'
RemainAfterExit=yes

View File

@ -1,9 +0,0 @@
[Unit]
Description=Delays the SONiC counters gathering until SONiC has started
[Timer]
OnBootSec=2min
Unit=enable_counters.service
[Install]
WantedBy=timers.target

View File

@ -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

View File

@ -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