@@ -49,7 +49,6 @@ func GetSystemStats() (*common.SystemStatsResponse, error) {
4949// Loopback interface (lo) is excluded from the calculation.
5050func getBandwidthSpeed () (uint64 , uint64 , error ) {
5151 // 1) First snapshot with timestamp
52- start := time .Now ()
5352 first , err := net .IOCounters (true )
5453 if err != nil {
5554 return 0 , 0 , err
@@ -63,15 +62,8 @@ func getBandwidthSpeed() (uint64, uint64, error) {
6362 if err != nil {
6463 return 0 , 0 , err
6564 }
66- end := time .Now ()
6765
68- // 4) Calculate actual elapsed time (not assumed 1 second)
69- actualDuration := end .Sub (start ).Seconds ()
70- if actualDuration == 0 {
71- return 0 , 0 , nil // avoid division by zero
72- }
73-
74- // 5) Build a map from interface name → first snapshot
66+ // 4) Build a map from interface name → first snapshot
7567 // Skip loopback interface
7668 prev := make (map [string ]net.IOCountersStat , len (first ))
7769 for _ , c := range first {
@@ -82,7 +74,7 @@ func getBandwidthSpeed() (uint64, uint64, error) {
8274 prev [c .Name ] = c
8375 }
8476
85- // 6 ) Compute deltas and sum across all interfaces
77+ // 5 ) Compute deltas and sum across all interfaces
8678 // Skip loopback interface
8779 var totalRxBytes , totalTxBytes uint64
8880 for _ , c := range second {
@@ -96,10 +88,6 @@ func getBandwidthSpeed() (uint64, uint64, error) {
9688 }
9789 }
9890
99- // 7) Convert bytes to bytes per second using ACTUAL measured time
100- rxPerSecond := uint64 (float64 (totalRxBytes ) / actualDuration )
101- txPerSecond := uint64 (float64 (totalTxBytes ) / actualDuration )
102-
103- // 8) Return the calculated rates (bytes per second)
104- return rxPerSecond , txPerSecond , nil
91+ // 6) Return the calculated rates (bytes per second)
92+ return totalRxBytes , totalTxBytes , nil
10593}
0 commit comments