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

Commit

Permalink
Add detailed memory usage labels to memory widget
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbassi committed May 24, 2018
1 parent ae2fff9 commit 42a949c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/widgets/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ func (self *CPU) update() {
key := "CPU" + strconv.Itoa(i)
percent := percents[i]
self.Data[key] = append(self.Data[key], percent)
self.Labels[key] = fmt.Sprintf("%3.0f%%", percent)
}
} else {
percent, _ := psCPU.Percent(self.interval, false)
self.Data["Average"] = append(self.Data["Average"], percent[0])
self.Labels["Average"] = fmt.Sprintf("%3.0f%%", percent[0])
}
}
9 changes: 9 additions & 0 deletions src/widgets/mem.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package widgets

import (
"fmt"
"time"

"github.com/cjbassi/gotop/src/utils"
ui "github.com/cjbassi/termui"
psMem "github.com/shirou/gopsutil/mem"
)
Expand Down Expand Up @@ -39,4 +41,11 @@ func (self *Mem) update() {
swap, _ := psMem.SwapMemory()
self.Data["Main"] = append(self.Data["Main"], main.UsedPercent)
self.Data["Swap"] = append(self.Data["Swap"], swap.UsedPercent)

mainTotalBytes, mainTotalMagnitude := utils.ConvertBytes(main.Total)
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)
}
9 changes: 4 additions & 5 deletions vendor/github.com/cjbassi/termui/linegraph.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 42a949c

Please sign in to comment.