mirror of
https://github.com/cjbassi/gotop.git
synced 2025-04-29 13:49:00 +08:00
Add detailed memory usage labels to memory widget
This commit is contained in:
parent
ae2fff9655
commit
42a949c5aa
2
Gopkg.lock
generated
2
Gopkg.lock
generated
@ -17,7 +17,7 @@
|
|||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/cjbassi/termui"
|
name = "github.com/cjbassi/termui"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "87dbce7f69558bede7c7c7a51324ce4d8cfcb87b"
|
revision = "9d77ad53bd1562d72b66b7ab5965e6495955846e"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
@ -67,9 +67,11 @@ func (self *CPU) update() {
|
|||||||
key := "CPU" + strconv.Itoa(i)
|
key := "CPU" + strconv.Itoa(i)
|
||||||
percent := percents[i]
|
percent := percents[i]
|
||||||
self.Data[key] = append(self.Data[key], percent)
|
self.Data[key] = append(self.Data[key], percent)
|
||||||
|
self.Labels[key] = fmt.Sprintf("%3.0f%%", percent)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
percent, _ := psCPU.Percent(self.interval, false)
|
percent, _ := psCPU.Percent(self.interval, false)
|
||||||
self.Data["Average"] = append(self.Data["Average"], percent[0])
|
self.Data["Average"] = append(self.Data["Average"], percent[0])
|
||||||
|
self.Labels["Average"] = fmt.Sprintf("%3.0f%%", percent[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package widgets
|
package widgets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/cjbassi/gotop/src/utils"
|
||||||
ui "github.com/cjbassi/termui"
|
ui "github.com/cjbassi/termui"
|
||||||
psMem "github.com/shirou/gopsutil/mem"
|
psMem "github.com/shirou/gopsutil/mem"
|
||||||
)
|
)
|
||||||
@ -39,4 +41,11 @@ func (self *Mem) update() {
|
|||||||
swap, _ := psMem.SwapMemory()
|
swap, _ := psMem.SwapMemory()
|
||||||
self.Data["Main"] = append(self.Data["Main"], main.UsedPercent)
|
self.Data["Main"] = append(self.Data["Main"], main.UsedPercent)
|
||||||
self.Data["Swap"] = append(self.Data["Swap"], swap.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
vendor/github.com/cjbassi/termui/linegraph.go
generated
vendored
9
vendor/github.com/cjbassi/termui/linegraph.go
generated
vendored
@ -1,7 +1,6 @@
|
|||||||
package termui
|
package termui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
drawille "github.com/cjbassi/drawille-go"
|
drawille "github.com/cjbassi/drawille-go"
|
||||||
@ -13,6 +12,7 @@ type LineGraph struct {
|
|||||||
Data map[string][]float64
|
Data map[string][]float64
|
||||||
LineColor map[string]Color
|
LineColor map[string]Color
|
||||||
Zoom int
|
Zoom int
|
||||||
|
Labels map[string]string
|
||||||
|
|
||||||
DefaultLineColor Color
|
DefaultLineColor Color
|
||||||
}
|
}
|
||||||
@ -23,6 +23,7 @@ func NewLineGraph() *LineGraph {
|
|||||||
Block: NewBlock(),
|
Block: NewBlock(),
|
||||||
Data: make(map[string][]float64),
|
Data: make(map[string][]float64),
|
||||||
LineColor: make(map[string]Color),
|
LineColor: make(map[string]Color),
|
||||||
|
Labels: make(map[string]string),
|
||||||
Zoom: 5,
|
Zoom: 5,
|
||||||
|
|
||||||
DefaultLineColor: Theme.LineGraph,
|
DefaultLineColor: Theme.LineGraph,
|
||||||
@ -103,17 +104,15 @@ func (self *LineGraph) Buffer() *Buffer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// renders key ontop
|
// renders key/label ontop
|
||||||
for j, seriesName := range seriesList {
|
for j, seriesName := range seriesList {
|
||||||
// sorts lines again
|
|
||||||
seriesData := self.Data[seriesName]
|
|
||||||
seriesLineColor, ok := self.LineColor[seriesName]
|
seriesLineColor, ok := self.LineColor[seriesName]
|
||||||
if !ok {
|
if !ok {
|
||||||
seriesLineColor = self.DefaultLineColor
|
seriesLineColor = self.DefaultLineColor
|
||||||
}
|
}
|
||||||
|
|
||||||
// render key ontop, but let braille be drawn over space characters
|
// render key ontop, but let braille be drawn over space characters
|
||||||
str := fmt.Sprintf("%s %3.0f%%", seriesName, seriesData[len(seriesData)-1])
|
str := seriesName + " " + self.Labels[seriesName]
|
||||||
for k, char := range str {
|
for k, char := range str {
|
||||||
if char != ' ' {
|
if char != ' ' {
|
||||||
buf.SetCell(3+k, j+2, Cell{char, seriesLineColor, self.Bg})
|
buf.SetCell(3+k, j+2, Cell{char, seriesLineColor, self.Bg})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user