Use interface details to populate the ifmib, on startup and after each event
This commit is contained in:
@@ -17,6 +17,9 @@ import (
|
||||
|
||||
type StatsCallback func(*api.InterfaceStats)
|
||||
|
||||
// Global callback for interface events
|
||||
var interfaceEventCallback InterfaceEventCallback
|
||||
|
||||
var (
|
||||
// Flags for VPP stats configuration
|
||||
ApiAddr = flag.String("vppstats.api.addr", "/var/run/vpp/api.sock", "VPP API socket path")
|
||||
@@ -25,6 +28,11 @@ var (
|
||||
Period = flag.Int("vppstats.period", 10, "Interval in seconds for querying VPP interface stats")
|
||||
)
|
||||
|
||||
// SetInterfaceEventCallback sets the callback for interface events
|
||||
func SetInterfaceEventCallback(callback InterfaceEventCallback) {
|
||||
interfaceEventCallback = callback
|
||||
}
|
||||
|
||||
// StartStatsRoutine starts a goroutine that queries VPP interface stats at the configured interval
|
||||
func StartStatsRoutine(callback StatsCallback) {
|
||||
period := time.Duration(*Period) * time.Second
|
||||
@@ -139,11 +147,22 @@ func statsRoutine(period time.Duration, callback StatsCallback) {
|
||||
logger.Debugf("Failed to create API channel for interface events: %v", err)
|
||||
} else {
|
||||
logger.Debugf("API channel created successfully, calling WatchInterfaceEvents...")
|
||||
if err := WatchInterfaceEvents(ch); err != nil {
|
||||
if err := WatchInterfaceEvents(ch, interfaceEventCallback); err != nil {
|
||||
logger.Debugf("Failed to start interface event watching: %v", err)
|
||||
ch.Close()
|
||||
} else {
|
||||
logger.Printf("Interface event watching started successfully")
|
||||
|
||||
// Do initial retrieval of interface details
|
||||
if interfaceEventCallback != nil {
|
||||
details, err := GetAllInterfaceDetails(ch)
|
||||
if err != nil {
|
||||
logger.Debugf("Failed to get initial interface details: %v", err)
|
||||
} else {
|
||||
logger.Debugf("Retrieved initial interface details for %d interfaces", len(details))
|
||||
interfaceEventCallback(details)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user