Simplify - only use queryInterfaceStats() and always do liveness check within it
This commit is contained in:
@ -133,7 +133,7 @@ func statsRoutine(period time.Duration, callback StatsCallback) {
|
||||
|
||||
// Query stats if connected
|
||||
if connected {
|
||||
if !queryInterfaceStatsWithLivenessCheck(conn, statsConn, callback) {
|
||||
if !queryInterfaceStats(conn, statsConn, callback) {
|
||||
connected = false
|
||||
continue
|
||||
}
|
||||
@ -147,7 +147,7 @@ func statsRoutine(period time.Duration, callback StatsCallback) {
|
||||
}
|
||||
}
|
||||
|
||||
func queryInterfaceStatsWithLivenessCheck(conn *core.Connection, statsConn *core.StatsConnection, callback StatsCallback) bool {
|
||||
func queryInterfaceStats(conn *core.Connection, statsConn *core.StatsConnection, callback StatsCallback) bool {
|
||||
// Check VPP liveness using API call
|
||||
if !checkVPPLiveness(conn) {
|
||||
logger.Printf("VPP liveness check failed")
|
||||
@ -233,30 +233,3 @@ func checkVPPLiveness(conn *core.Connection) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Keep the old function for compatibility
|
||||
func queryInterfaceStats(c *core.StatsConnection, callback StatsCallback) {
|
||||
// Create the proper struct for interface stats
|
||||
stats := new(api.InterfaceStats)
|
||||
|
||||
// Use the GetInterfaceStats method - this is the correct approach
|
||||
if err := c.GetInterfaceStats(stats); err != nil {
|
||||
logger.Printf("Failed to get interface stats: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Always log basic info
|
||||
logger.Printf("Retrieved stats for %d interfaces", len(stats.Interfaces))
|
||||
|
||||
// Debug logging for individual interfaces
|
||||
for _, iface := range stats.Interfaces {
|
||||
logger.Debugf("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)
|
||||
}
|
||||
|
||||
// Call the callback to update the MIB
|
||||
if callback != nil {
|
||||
callback(stats)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user