diff --git a/main.go b/main.go index f845f28..47c18c5 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,8 @@ import ( func main() { addr := flag.String("agentx-addr", "localhost:705", "Address to connect to (hostname:port or Unix socket path)") + vppStatsAddr := flag.String("vpp-stats-addr", "/var/run/vpp/stats.sock", "VPP stats socket path") + period := flag.Float64("period", 10.0, "Interval in seconds for querying VPP interface stats") flag.Parse() var network, address string @@ -32,7 +34,7 @@ func main() { client.ReconnectInterval = 1 * time.Second // Start VPP stats routine - vppstats.StartStatsRoutine() + vppstats.StartStatsRoutine(*vppStatsAddr, time.Duration(*period*1000)*time.Millisecond) for { time.Sleep(100 * time.Millisecond) diff --git a/vppstats/stats.go b/vppstats/stats.go index 3aa1fce..3a49dcb 100644 --- a/vppstats/stats.go +++ b/vppstats/stats.go @@ -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 {