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

Commit

Permalink
Net and ram formatted to 1 decimal place
Browse files Browse the repository at this point in the history
Closes #51
  • Loading branch information
cjbassi committed Aug 23, 2018
1 parent af674fd commit d14e09c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/widgets/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ func (self *Mem) update() {
swapTotalBytes, swapTotalMagnitude := utils.ConvertBytes(swap.Total)
mainUsedBytes, mainUsedMagnitude := utils.ConvertBytes(main.Used)
swapUsedBytes, swapUsedMagnitude := utils.ConvertBytes(swap.Used)
self.Labels["Main"] = fmt.Sprintf("%3.0f%% %.0f%s/%.0f%s", main.UsedPercent, mainUsedBytes, mainUsedMagnitude, mainTotalBytes, mainTotalMagnitude)
self.Labels["Swap"] = fmt.Sprintf("%3.0f%% %.0f%s/%.0f%s", swap.UsedPercent, swapUsedBytes, swapUsedMagnitude, swapTotalBytes, swapTotalMagnitude)
self.Labels["Main"] = fmt.Sprintf("%3.0f%% %5.1f%s/%.0f%s", main.UsedPercent, mainUsedBytes, mainUsedMagnitude, mainTotalBytes, mainTotalMagnitude)
self.Labels["Swap"] = fmt.Sprintf("%3.0f%% %5.1f%s/%.0f%s", swap.UsedPercent, swapUsedBytes, swapUsedMagnitude, swapTotalBytes, swapTotalMagnitude)
}
36 changes: 16 additions & 20 deletions src/widgets/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ func (self *Net) update() {
interfaces, _ := psNet.IOCounters(false)
curRecvTotal := interfaces[0].BytesRecv
curSentTotal := interfaces[0].BytesSent
var recvRecent uint64 = 0
var sentRecent uint64 = 0

if self.prevRecvTotal != 0 { // if this isn't the first update
recvRecent := curRecvTotal - self.prevRecvTotal
sentRecent := curSentTotal - self.prevSentTotal
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))
Expand All @@ -77,23 +79,17 @@ func (self *Net) update() {

// render widget titles
for i := 0; i < 2; i++ {
var method string // either 'Rx' or 'Tx'
var total float64
recent := self.Lines[i].Data[len(self.Lines[i].Data)-1]

if i == 0 {
total = float64(curRecvTotal)
method = "Rx"
} else {
total = float64(curSentTotal)
method = "Tx"
}

recentFloat, unitRecent := utils.ConvertBytes(uint64(recent))
recent = int(recentFloat)
total, unitTotal := utils.ConvertBytes(uint64(total))

self.Lines[i].Title1 = fmt.Sprintf(" Total %s: %5.1f %s", method, total, unitTotal)
self.Lines[i].Title2 = fmt.Sprintf(" %s/s: %9d %2s/s", method, recent, unitRecent)
total, label, recent := func() (uint64, string, uint64) {
if i == 0 {
return curRecvTotal, "RX", recvRecent
}
return curSentTotal, "Tx", sentRecent
}()

recentConv, unitRecent := utils.ConvertBytes(uint64(recent))
totalConv, unitTotal := utils.ConvertBytes(uint64(total))

self.Lines[i].Title1 = fmt.Sprintf(" Total %s: %5.1f %s", label, totalConv, unitTotal)
self.Lines[i].Title2 = fmt.Sprintf(" %s/s: %9.1f %2s/s", label, recentConv, unitRecent)
}
}

0 comments on commit d14e09c

Please sign in to comment.