Skip to content

Commit 0088e4d

Browse files
committed
fix: net stats data overflowing
1 parent 14dedf1 commit 0088e4d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

host/net.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ func netStats() (*NetStat, error) {
1818
if err != nil {
1919
return nil, err
2020
}
21-
IO := make(map[string][]int32)
21+
IO := make(map[string][]uint64)
2222
for _, IOStat := range netStats {
23-
nic := []int32{int32(IOStat.BytesSent), int32(IOStat.BytesRecv)}
23+
nic := []uint64{IOStat.BytesSent, IOStat.BytesRecv}
2424
IO[IOStat.Name] = nic
2525
}
2626
if len(IO) == 0 {
@@ -33,8 +33,8 @@ func netStats() (*NetStat, error) {
3333
return nil, errors.New("interface not found")
3434
}
3535
allNet := IO["all"]
36-
currentBytesSent := uint64(allNet[0])
37-
currentBytesRecv := uint64(allNet[1])
36+
currentBytesSent := allNet[0]
37+
currentBytesRecv := allNet[1]
3838
bytesSent := currentBytesSent - lastCurrentBytesSent
3939
bytesRecv := currentBytesRecv - lastCurrentBytesRecv
4040
lastCurrentBytesSent = currentBytesSent
@@ -52,7 +52,7 @@ func netStats() (*NetStat, error) {
5252
bytesRecv = 0
5353
}
5454
return &NetStat{
55-
SentKB: uint64(bytesSent / 1024),
56-
RecvKB: uint64(bytesRecv / 1024),
55+
SentKB: bytesSent / 1024,
56+
RecvKB: bytesRecv / 1024,
5757
}, nil
5858
}

0 commit comments

Comments
 (0)