Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Fix double counting network data with VPN (Close #61)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbassi committed Dec 10, 2018
1 parent defda4a commit f5ad5e8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/widgets/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ func NewNet() *Net {
}

func (self *Net) update() {
// `false` causes psutil to group all network activity
interfaces, err := psNet.IOCounters(false)
interfaces, err := psNet.IOCounters(true)
if err != nil {
log.Printf("failed to get network activity from gopsutil: %v", err)
}
curRecvTotal := interfaces[0].BytesRecv
curSentTotal := interfaces[0].BytesSent
var curRecvTotal uint64
var curSentTotal uint64
for _, _interface := range interfaces {
// ignore VPN interface
if _interface.Name != "tun0" {
curRecvTotal += _interface.BytesRecv
curSentTotal += _interface.BytesSent
}
}
var recvRecent uint64
var sentRecent uint64

Expand Down

0 comments on commit f5ad5e8

Please sign in to comment.