add -period flag

This commit is contained in:
Pim van Pelt
2025-06-09 17:20:58 +02:00
parent 6d6856d206
commit d4769d6cdb
2 changed files with 10 additions and 8 deletions

View File

@ -9,16 +9,16 @@ import (
"go.fd.io/govpp/core"
)
// StartStatsRoutine starts a goroutine that queries VPP interface stats every 10 seconds
func StartStatsRoutine() {
go statsRoutine()
// StartStatsRoutine starts a goroutine that queries VPP interface stats at the specified interval
func StartStatsRoutine(statsSocketPath string, period time.Duration) {
go statsRoutine(statsSocketPath, period)
}
func statsRoutine() {
log.Println("Starting VPP stats routine...")
func statsRoutine(statsSocketPath string, period time.Duration) {
log.Printf("Starting VPP stats routine with socket: %s, period: %v", statsSocketPath, period)
// Create stats client
client := statsclient.NewStatsClient("/var/run/vpp/stats.sock")
client := statsclient.NewStatsClient(statsSocketPath)
// Connect using core.ConnectStats (proper way)
c, err := core.ConnectStats(client)
@ -28,7 +28,7 @@ func statsRoutine() {
}
defer c.Disconnect()
ticker := time.NewTicker(10 * time.Second)
ticker := time.NewTicker(period)
defer ticker.Stop()
for {