add -period flag
This commit is contained in:
4
main.go
4
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)
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user