This commit is contained in:
Toby Chui 2024-11-17 08:38:13 +08:00
parent ec5c24b9b8
commit 1c79fa4e96

View File

@ -169,9 +169,16 @@ func (n *NetStatBuffers) HandleGetBufferedNetworkInterfaceStats(w http.ResponseW
} }
func (n *NetStatBuffers) Close() { func (n *NetStatBuffers) Close() {
n.StopChan <- true //Fixed issue #394 for stopping netstat listener on platforms not supported platforms
time.Sleep(300 * time.Millisecond) if n.StopChan != nil {
n.EventTicker.Stop() n.StopChan <- true
time.Sleep(300 * time.Millisecond)
}
if n.EventTicker != nil {
n.EventTicker.Stop()
}
} }
func (n *NetStatBuffers) HandleGetNetworkInterfaceStats(w http.ResponseWriter, r *http.Request) { func (n *NetStatBuffers) HandleGetNetworkInterfaceStats(w http.ResponseWriter, r *http.Request) {
@ -270,11 +277,11 @@ func (n *NetStatBuffers) GetNetworkInterfaceStats() (int64, int64, error) {
allIfaceRxByteFiles, err := filepath.Glob("/sys/class/net/*/statistics/rx_bytes") allIfaceRxByteFiles, err := filepath.Glob("/sys/class/net/*/statistics/rx_bytes")
if err != nil { if err != nil {
//Permission denied //Permission denied
return 0, 0, errors.New("Access denied") return 0, 0, errors.New("access denied")
} }
if len(allIfaceRxByteFiles) == 0 { if len(allIfaceRxByteFiles) == 0 {
return 0, 0, errors.New("No valid iface found") return 0, 0, errors.New("no valid iface found")
} }
rxSum := int64(0) rxSum := int64(0)
@ -334,5 +341,5 @@ func (n *NetStatBuffers) GetNetworkInterfaceStats() (int64, int64, error) {
return 0, 0, nil //no ethernet adapters with en*/<Link#*> return 0, 0, nil //no ethernet adapters with en*/<Link#*>
} }
return 0, 0, errors.New("Platform not supported") return 0, 0, errors.New("platform not supported")
} }