Move flags to their own modules

This commit is contained in:
Pim van Pelt
2025-06-09 18:18:38 +02:00
parent fb3c545e11
commit b6cdcd16ba
4 changed files with 23 additions and 17 deletions

View File

@ -1,6 +1,7 @@
package vppstats
import (
"flag"
"log"
"time"
@ -13,16 +14,24 @@ import (
type StatsCallback func(*api.InterfaceStats)
// StartStatsRoutine starts a goroutine that queries VPP interface stats at the specified interval
func StartStatsRoutine(statsSocketPath string, period time.Duration, callback StatsCallback) {
go statsRoutine(statsSocketPath, period, callback)
var (
// Flags for VPP stats configuration
StatsAddr = flag.String("vppstats.addr", "/var/run/vpp/stats.sock", "VPP stats socket path")
IfIndexOffset = flag.Int("vppstats.ifindex-offset", 1000, "Offset to add to VPP interface indices for SNMP")
Period = flag.Int("vppstats.period", 10, "Interval in seconds for querying VPP interface stats")
)
// StartStatsRoutine starts a goroutine that queries VPP interface stats at the configured interval
func StartStatsRoutine(callback StatsCallback) {
period := time.Duration(*Period) * time.Second
go statsRoutine(period, callback)
}
func statsRoutine(statsSocketPath string, period time.Duration, callback StatsCallback) {
logger.Debugf("Starting VPP stats routine with socket: %s, period: %v", statsSocketPath, period)
func statsRoutine(period time.Duration, callback StatsCallback) {
logger.Debugf("Starting VPP stats routine with socket: %s, period: %v", *StatsAddr, period)
// Create stats client
client := statsclient.NewStatsClient(statsSocketPath)
client := statsclient.NewStatsClient(*StatsAddr)
// Connect using core.ConnectStats (proper way)
c, err := core.ConnectStats(client)