add -period flag
This commit is contained in:
4
main.go
4
main.go
@ -13,6 +13,8 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
addr := flag.String("agentx-addr", "localhost:705", "Address to connect to (hostname:port or Unix socket path)")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
var network, address string
|
var network, address string
|
||||||
@ -32,7 +34,7 @@ func main() {
|
|||||||
client.ReconnectInterval = 1 * time.Second
|
client.ReconnectInterval = 1 * time.Second
|
||||||
|
|
||||||
// Start VPP stats routine
|
// Start VPP stats routine
|
||||||
vppstats.StartStatsRoutine()
|
vppstats.StartStatsRoutine(*vppStatsAddr, time.Duration(*period*1000)*time.Millisecond)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
@ -9,16 +9,16 @@ import (
|
|||||||
"go.fd.io/govpp/core"
|
"go.fd.io/govpp/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StartStatsRoutine starts a goroutine that queries VPP interface stats every 10 seconds
|
// StartStatsRoutine starts a goroutine that queries VPP interface stats at the specified interval
|
||||||
func StartStatsRoutine() {
|
func StartStatsRoutine(statsSocketPath string, period time.Duration) {
|
||||||
go statsRoutine()
|
go statsRoutine(statsSocketPath, period)
|
||||||
}
|
}
|
||||||
|
|
||||||
func statsRoutine() {
|
func statsRoutine(statsSocketPath string, period time.Duration) {
|
||||||
log.Println("Starting VPP stats routine...")
|
log.Printf("Starting VPP stats routine with socket: %s, period: %v", statsSocketPath, period)
|
||||||
|
|
||||||
// Create stats client
|
// Create stats client
|
||||||
client := statsclient.NewStatsClient("/var/run/vpp/stats.sock")
|
client := statsclient.NewStatsClient(statsSocketPath)
|
||||||
|
|
||||||
// Connect using core.ConnectStats (proper way)
|
// Connect using core.ConnectStats (proper way)
|
||||||
c, err := core.ConnectStats(client)
|
c, err := core.ConnectStats(client)
|
||||||
@ -28,7 +28,7 @@ func statsRoutine() {
|
|||||||
}
|
}
|
||||||
defer c.Disconnect()
|
defer c.Disconnect()
|
||||||
|
|
||||||
ticker := time.NewTicker(10 * time.Second)
|
ticker := time.NewTicker(period)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
Reference in New Issue
Block a user