summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2018-04-10 21:34:11 -0700
committerCaleb Bassi <calebjbassi@gmail.com>2018-04-10 21:38:01 -0700
commit9bd89b17893057cc11e17d4990c9bf1c0171439c (patch)
treee72e4f0b3759940bff5110f8299b1512974c957b
parent08e981218d8efd83d515ba482e6b2e7934b84f46 (diff)
Add logging to net data
-rw-r--r--widgets/net.go36
1 files changed, 24 insertions, 12 deletions
diff --git a/widgets/net.go b/widgets/net.go
index cddfebf..1155db3 100644
--- a/widgets/net.go
+++ b/widgets/net.go
@@ -13,8 +13,8 @@ type Net struct {
*ui.Sparklines
interval time.Duration
// used to calculate recent network activity
- recvTotal uint64
- sentTotal uint64
+ prevRecvTotal uint64
+ prevSentTotal uint64
}
func NewNet() *Net {
@@ -45,22 +45,34 @@ func NewNet() *Net {
func (self *Net) update() {
// `false` causes psutil to group all network activity
interfaces, _ := psNet.IOCounters(false)
- recvTotal := interfaces[0].BytesRecv
- sentTotal := interfaces[0].BytesSent
+ curRecvTotal := interfaces[0].BytesRecv
+ curSentTotal := interfaces[0].BytesSent
- if self.recvTotal != 0 { // if this isn't the first update
- recvRecent := recvTotal - self.recvTotal
- sentRecent := sentTotal - self.sentTotal
+ if self.prevRecvTotal != 0 { // if this isn't the first update
+ recvRecent := curRecvTotal - self.prevRecvTotal
+ sentRecent := curSentTotal - self.prevSentTotal
self.Lines[0].Data = append(self.Lines[0].Data, int(recvRecent))
self.Lines[1].Data = append(self.Lines[1].Data, int(sentRecent))
+
+ if recvRecent < 0 || sentRecent < 0 {
+ utils.Error("net data",
+ fmt.Sprint(
+ "curRecvTotal: ", curRecvTotal, "\n",
+ "curSentTotal: ", curSentTotal, "\n",
+ "self.prevRecvTotal: ", self.prevRecvTotal, "\n",
+ "self.prevSentTotal: ", self.prevSentTotal, "\n",
+ "recvRecent: ", recvRecent, "\n",
+ "sentRecent: ", sentRecent,
+ ))
+ }
}
// used in later calls to update
- self.recvTotal = recvTotal
- self.sentTotal = sentTotal
+ self.prevRecvTotal = curRecvTotal
+ self.prevSentTotal = curSentTotal
- // renders net widget titles
+ // net widget titles
for i := 0; i < 2; i++ {
var method string // either 'Rx' or 'Tx'
var total float64
@@ -69,10 +81,10 @@ func (self *Net) update() {
unitRecent := "B"
if i == 0 {
- total = float64(recvTotal)
+ total = float64(curRecvTotal)
method = "Rx"
} else {
- total = float64(sentTotal)
+ total = float64(curSentTotal)
method = "Tx"
}