GetInterfaceStats returns RX/TX statistics for the interface
()
| 299 | |
| 300 | // GetInterfaceStats returns RX/TX statistics for the interface |
| 301 | func (m *Manager) GetInterfaceStats() (rxBytes, txBytes int64, err error) { |
| 302 | m.mu.RLock() |
| 303 | defer m.mu.RUnlock() |
| 304 | |
| 305 | nl := m.getNetlinkOps() |
| 306 | link, err := nl.LinkByName(m.iFaceName) |
| 307 | if err != nil { |
| 308 | return 0, 0, fmt.Errorf("failed to get link: %w", err) |
| 309 | } |
| 310 | |
| 311 | stats := link.Attrs().Statistics |
| 312 | if stats == nil { |
| 313 | return 0, 0, nil |
| 314 | } |
| 315 | |
| 316 | return int64(stats.RxBytes), int64(stats.TxBytes), nil |
| 317 | } |
no test coverage detected