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:34:11 -0700
commit286123f3c9768d6cc3a6b6f90644d7434340ff3b (patch)
treebf7c17151d3bbca704ae862713ff534fe961c886
parent08e981218d8efd83d515ba482e6b2e7934b84f46 (diff)
Add logging to net data1.2.7
-rw-r--r--widgets/net.go37
1 files changed, 25 insertions, 12 deletions
diff --git a/widgets/net.go b/widgets/net.go
index cddfebf..4c5c62d 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,35 @@ 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 {
+ if true {
+ 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 +82,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"
}