mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
update memory gauge labelling
This commit is contained in:
26
container.go
26
container.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/fsouza/go-dockerclient"
|
"github.com/fsouza/go-dockerclient"
|
||||||
ui "github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
@@ -61,13 +62,34 @@ func (c *Container) Collect(client *docker.Client) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) UpdateCPU(n int) {
|
func (c *Container) UpdateCPU(total uint64, system uint64) {
|
||||||
c.widgets.cpu.BarColor = colorScale(n)
|
c.widgets.cpu.BarColor = colorScale(n)
|
||||||
c.widgets.cpu.Percent = n
|
c.widgets.cpu.Percent = n
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) UpdateMem(cur uint64, limit uint64) {
|
func (c *Container) UpdateMem(cur uint64, limit uint64) {
|
||||||
c.widgets.memory.Percent = round((float64(cur) / float64(limit)) * 100)
|
percent := round((float64(cur) / float64(limit)) * 100)
|
||||||
|
if percent < 5 {
|
||||||
|
percent = 5
|
||||||
|
}
|
||||||
|
c.widgets.memory.Percent = percent
|
||||||
|
c.widgets.memory.Label = fmt.Sprintf("%s / %s", byteFormat(cur), byteFormat(limit))
|
||||||
|
}
|
||||||
|
|
||||||
|
func byteFormat(n uint64) string {
|
||||||
|
if n < 1024 {
|
||||||
|
return fmt.Sprintf("%sB", strconv.FormatUint(n, 10))
|
||||||
|
}
|
||||||
|
if n < 1048576 {
|
||||||
|
n = n / 1024
|
||||||
|
return fmt.Sprintf("%sK", strconv.FormatUint(n, 10))
|
||||||
|
}
|
||||||
|
if n < 1073741824 {
|
||||||
|
n = n / 1048576
|
||||||
|
return fmt.Sprintf("%sM", strconv.FormatUint(n, 10))
|
||||||
|
}
|
||||||
|
n = n / 1024000000
|
||||||
|
return fmt.Sprintf("%sG", strconv.FormatUint(n, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
func round(num float64) int {
|
func round(num float64) int {
|
||||||
|
|||||||
3
grid.go
3
grid.go
@@ -40,9 +40,10 @@ func mkGauge() *ui.Gauge {
|
|||||||
g := ui.NewGauge()
|
g := ui.NewGauge()
|
||||||
g.Height = 1
|
g.Height = 1
|
||||||
g.Border = false
|
g.Border = false
|
||||||
g.Percent = 5
|
g.Percent = 0
|
||||||
g.PaddingBottom = 0
|
g.PaddingBottom = 0
|
||||||
g.BarColor = ui.ColorGreen
|
g.BarColor = ui.ColorGreen
|
||||||
|
g.Label = "-"
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user