Add -vpp-ifindex-offset flag
This commit is contained in:
@ -9,12 +9,14 @@ import (
|
||||
"go.fd.io/govpp/core"
|
||||
)
|
||||
|
||||
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) {
|
||||
go statsRoutine(statsSocketPath, period)
|
||||
func StartStatsRoutine(statsSocketPath string, period time.Duration, callback StatsCallback) {
|
||||
go statsRoutine(statsSocketPath, period, callback)
|
||||
}
|
||||
|
||||
func statsRoutine(statsSocketPath string, period time.Duration) {
|
||||
func statsRoutine(statsSocketPath string, period time.Duration, callback StatsCallback) {
|
||||
log.Printf("Starting VPP stats routine with socket: %s, period: %v", statsSocketPath, period)
|
||||
|
||||
// Create stats client
|
||||
@ -29,7 +31,7 @@ func statsRoutine(statsSocketPath string, period time.Duration) {
|
||||
defer c.Disconnect()
|
||||
|
||||
// Query stats immediately on startup
|
||||
queryInterfaceStats(c)
|
||||
queryInterfaceStats(c, callback)
|
||||
|
||||
ticker := time.NewTicker(period)
|
||||
defer ticker.Stop()
|
||||
@ -37,12 +39,12 @@ func statsRoutine(statsSocketPath string, period time.Duration) {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
queryInterfaceStats(c)
|
||||
queryInterfaceStats(c, callback)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func queryInterfaceStats(c *core.StatsConnection) {
|
||||
func queryInterfaceStats(c *core.StatsConnection, callback StatsCallback) {
|
||||
log.Printf("Querying VPP interface stats at %s", time.Now().Format(time.RFC3339))
|
||||
|
||||
// Create the proper struct for interface stats
|
||||
@ -54,14 +56,17 @@ func queryInterfaceStats(c *core.StatsConnection) {
|
||||
return
|
||||
}
|
||||
|
||||
// Now you have properly structured data
|
||||
// Log basic info
|
||||
log.Printf("Retrieved stats for %d interfaces", len(stats.Interfaces))
|
||||
for _, iface := range stats.Interfaces {
|
||||
log.Printf("Interface %d (%s):", iface.InterfaceIndex, iface.InterfaceName)
|
||||
log.Printf(" RX: %d packets, %d bytes", iface.Rx.Packets, iface.Rx.Bytes)
|
||||
log.Printf(" TX: %d packets, %d bytes", iface.Tx.Packets, iface.Tx.Bytes)
|
||||
log.Printf(" RX Errors: %d, TX Errors: %d", iface.RxErrors, iface.TxErrors)
|
||||
log.Printf(" Drops: %d, Punts: %d", iface.Drops, iface.Punts)
|
||||
log.Printf("Interface %d (%s): RX %d pkts/%d bytes, TX %d pkts/%d bytes",
|
||||
iface.InterfaceIndex, iface.InterfaceName,
|
||||
iface.Rx.Packets, iface.Rx.Bytes,
|
||||
iface.Tx.Packets, iface.Tx.Bytes)
|
||||
}
|
||||
|
||||
log.Printf("Retrieved stats for %d interfaces", len(stats.Interfaces))
|
||||
// Call the callback to update the MIB
|
||||
if callback != nil {
|
||||
callback(stats)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user