|
@@ -74,6 +74,17 @@ func NewNetStatBuffer(recordCount int) (*NetStatBuffers, error) {
|
|
|
log.Println("Unable to get NIC stats: ", err.Error())
|
|
|
}
|
|
|
|
|
|
+ retryCount := 0
|
|
|
+ for rx == 0 && tx == 0 && retryCount < 10 {
|
|
|
+ //Strange. Retry
|
|
|
+ log.Println("NIC stats return all 0. Retrying...")
|
|
|
+ rx, tx, err = GetNetworkInterfaceStats()
|
|
|
+ if err != nil {
|
|
|
+ log.Println("Unable to get NIC stats: ", err.Error())
|
|
|
+ }
|
|
|
+ retryCount++
|
|
|
+ }
|
|
|
+
|
|
|
n.PreviousStat = &RawFlowStat{
|
|
|
RX: rx,
|
|
|
TX: tx,
|
|
@@ -85,12 +96,13 @@ func NewNetStatBuffer(recordCount int) (*NetStatBuffers, error) {
|
|
|
go func(n *NetStatBuffers) {
|
|
|
for {
|
|
|
select {
|
|
|
- case <-stopCh:
|
|
|
+ case <-n.StopChan:
|
|
|
return
|
|
|
|
|
|
case <-ticker.C:
|
|
|
if n.PreviousStat.RX == 0 && n.PreviousStat.TX == 0 {
|
|
|
//Initiation state is still not done. Ignore request
|
|
|
+ log.Println("No initial states. Waiting")
|
|
|
return
|
|
|
}
|
|
|
// Get the latest network interface stats
|
|
@@ -159,6 +171,7 @@ func (n *NetStatBuffers) HandleGetBufferedNetworkInterfaceStats(w http.ResponseW
|
|
|
|
|
|
func (n *NetStatBuffers) Close() {
|
|
|
n.StopChan <- true
|
|
|
+ time.Sleep(time.Second)
|
|
|
n.EventTicker.Stop()
|
|
|
}
|
|
|
|
|
@@ -190,6 +203,8 @@ func GetNetworkInterfaceStats() (int64, int64, error) {
|
|
|
return 0, 0, err
|
|
|
}
|
|
|
|
|
|
+ defer cmd.Process.Kill()
|
|
|
+
|
|
|
//Filter out the first line
|
|
|
|
|
|
lines := strings.Split(strings.ReplaceAll(string(out), "\r\n", "\n"), "\n")
|