mirror of https://github.com/cjbassi/gotop.git
parent
af674fd6f0
commit
d14e09c34f
|
@ -46,6 +46,6 @@ func (self *Mem) update() {
|
||||||
swapTotalBytes, swapTotalMagnitude := utils.ConvertBytes(swap.Total)
|
swapTotalBytes, swapTotalMagnitude := utils.ConvertBytes(swap.Total)
|
||||||
mainUsedBytes, mainUsedMagnitude := utils.ConvertBytes(main.Used)
|
mainUsedBytes, mainUsedMagnitude := utils.ConvertBytes(main.Used)
|
||||||
swapUsedBytes, swapUsedMagnitude := utils.ConvertBytes(swap.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["Main"] = fmt.Sprintf("%3.0f%% %5.1f%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["Swap"] = fmt.Sprintf("%3.0f%% %5.1f%s/%.0f%s", swap.UsedPercent, swapUsedBytes, swapUsedMagnitude, swapTotalBytes, swapTotalMagnitude)
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,10 +48,12 @@ func (self *Net) update() {
|
||||||
interfaces, _ := psNet.IOCounters(false)
|
interfaces, _ := psNet.IOCounters(false)
|
||||||
curRecvTotal := interfaces[0].BytesRecv
|
curRecvTotal := interfaces[0].BytesRecv
|
||||||
curSentTotal := interfaces[0].BytesSent
|
curSentTotal := interfaces[0].BytesSent
|
||||||
|
var recvRecent uint64 = 0
|
||||||
|
var sentRecent uint64 = 0
|
||||||
|
|
||||||
if self.prevRecvTotal != 0 { // if this isn't the first update
|
if self.prevRecvTotal != 0 { // if this isn't the first update
|
||||||
recvRecent := curRecvTotal - self.prevRecvTotal
|
recvRecent = curRecvTotal - self.prevRecvTotal
|
||||||
sentRecent := curSentTotal - self.prevSentTotal
|
sentRecent = curSentTotal - self.prevSentTotal
|
||||||
|
|
||||||
self.Lines[0].Data = append(self.Lines[0].Data, int(recvRecent))
|
self.Lines[0].Data = append(self.Lines[0].Data, int(recvRecent))
|
||||||
self.Lines[1].Data = append(self.Lines[1].Data, int(sentRecent))
|
self.Lines[1].Data = append(self.Lines[1].Data, int(sentRecent))
|
||||||
|
@ -77,23 +79,17 @@ func (self *Net) update() {
|
||||||
|
|
||||||
// render widget titles
|
// render widget titles
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
var method string // either 'Rx' or 'Tx'
|
total, label, recent := func() (uint64, string, uint64) {
|
||||||
var total float64
|
if i == 0 {
|
||||||
recent := self.Lines[i].Data[len(self.Lines[i].Data)-1]
|
return curRecvTotal, "RX", recvRecent
|
||||||
|
}
|
||||||
|
return curSentTotal, "Tx", sentRecent
|
||||||
|
}()
|
||||||
|
|
||||||
if i == 0 {
|
recentConv, unitRecent := utils.ConvertBytes(uint64(recent))
|
||||||
total = float64(curRecvTotal)
|
totalConv, unitTotal := utils.ConvertBytes(uint64(total))
|
||||||
method = "Rx"
|
|
||||||
} else {
|
|
||||||
total = float64(curSentTotal)
|
|
||||||
method = "Tx"
|
|
||||||
}
|
|
||||||
|
|
||||||
recentFloat, unitRecent := utils.ConvertBytes(uint64(recent))
|
self.Lines[i].Title1 = fmt.Sprintf(" Total %s: %5.1f %s", label, totalConv, unitTotal)
|
||||||
recent = int(recentFloat)
|
self.Lines[i].Title2 = fmt.Sprintf(" %s/s: %9.1f %2s/s", label, recentConv, unitRecent)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue