Browse Source

fix traffic sent and recieved metric

Abhishek Kondur 2 years ago
parent
commit
a701956d99
1 changed files with 10 additions and 2 deletions
  1. 10 2
      mq/handlers.go

+ 10 - 2
mq/handlers.go

@@ -367,8 +367,16 @@ func updateNodeMetrics(currentNode *models.Node, newMetrics *models.Metrics) boo
 			currMetric.TotalReceived += oldMetric.TotalReceived
 			currMetric.TotalReceived += oldMetric.TotalReceived
 			currMetric.TotalSent += oldMetric.TotalSent
 			currMetric.TotalSent += oldMetric.TotalSent
 		} else {
 		} else {
-			currMetric.TotalReceived += int64(math.Abs(float64(currMetric.TotalReceived) - float64(oldMetric.TotalReceived)))
-			currMetric.TotalSent += int64(math.Abs(float64(currMetric.TotalSent) - float64(oldMetric.TotalSent)))
+			if currMetric.TotalReceived < oldMetric.TotalReceived {
+				currMetric.TotalReceived += oldMetric.TotalReceived
+			} else {
+				currMetric.TotalReceived += int64(math.Abs(float64(currMetric.TotalReceived) - float64(oldMetric.TotalReceived)))
+			}
+			if currMetric.TotalSent < oldMetric.TotalSent {
+				currMetric.TotalSent += oldMetric.TotalSent
+			} else {
+				currMetric.TotalSent += int64(math.Abs(float64(currMetric.TotalSent) - float64(oldMetric.TotalSent)))
+			}
 		}
 		}
 		if currMetric.Uptime == 0 || currMetric.TotalTime == 0 {
 		if currMetric.Uptime == 0 || currMetric.TotalTime == 0 {
 			currMetric.PercentUp = 0
 			currMetric.PercentUp = 0