Enable telemetry container on SONIC - mganugapati-auradine/sonic-buildimage GitHub Wiki
Enable Telemetry in SONiC Build
-
Edit build template: nano files/build_templates/init_cfg.json.j2
-
Add: "FEATURE": { "telemetry": { "state": "enabled" } }, "TELEMETRY": { "gnmi": { "port": "50051", "client_auth": "false" } },
-
Open the rules/config file and modify INCLUDE_SYSTEM_TELEMETRY = y
-
Create the file files/build_templates/docker_image_info.j2
"telemetry": { "container": "docker-sonic-telemetry", "options": "--net=host -p 50051:50051" }
-
Build: make clean
make configure PLATFORM=vs
make target/sonic-vs.img.gz
-
When you start the SONIC make sure to setup host forwarding from port 9339 on the host to 9339 inside the container
sudo pkill -f qemu-system- && sleep 1 && sudo qemu-system-x86_64 -enable-kvm -m 8192 -smp 4 -nographic -name sonic-vs -drive file=/home/mganugapati/sonic-buildimage/target/sonic-vs.img,format=qcow2,if=virtio -vga none -virtfs local,path=/home/mganugapati/sonic-buildimage/target,mount_tag=hostshare,security_model=passthrough,id=hostshare -netdev user,id=mynet0,hostfwd=tcp::**9339-:9339**
-device e1000,netdev=mynet0
-
After boot:
docker ps | grep telemetry
sudo netstat -tulnp | grep 9339
Explanation of what telemetry container does:
It separates and parses flags for both the logging system (glog) and telemetry-specific configurations, then builds a configuration struct to start the gNMI server. The server is designed to handle runtime signals (like SIGTERM) for graceful shutdown or restart. It also watches for changes to TLS certificate files using fsnotify, allowing the server to automatically reload certificates without downtime. TLS is strictly enforced unless explicitly disabled, and authentication methods (JWT, password, cert) are configured accordingly. The server is then started in a loop, allowing it to restart if needed due to certificate updates or external signals.