mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
add net rx/tx column
This commit is contained in:
parent
e5e84ee206
commit
1bbe8463fe
@ -43,6 +43,7 @@ func (c *Container) Collect(client *docker.Client) {
|
|||||||
c.reader.Read(s)
|
c.reader.Read(s)
|
||||||
c.widgets.SetCPU(c.reader.CPUUtil)
|
c.widgets.SetCPU(c.reader.CPUUtil)
|
||||||
c.widgets.SetMem(c.reader.MemUsage, c.reader.MemLimit)
|
c.widgets.SetMem(c.reader.MemUsage, c.reader.MemLimit)
|
||||||
|
c.widgets.SetNet(c.reader.NetRx, c.reader.NetTx)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
11
grid.go
11
grid.go
@ -31,35 +31,36 @@ func (g *Grid) Rows() (rows []*ui.Row) {
|
|||||||
ui.NewCol(1, 0, c.widgets.cid),
|
ui.NewCol(1, 0, c.widgets.cid),
|
||||||
ui.NewCol(2, 0, c.widgets.cpu),
|
ui.NewCol(2, 0, c.widgets.cpu),
|
||||||
ui.NewCol(2, 0, c.widgets.memory),
|
ui.NewCol(2, 0, c.widgets.memory),
|
||||||
|
ui.NewCol(2, 0, c.widgets.net),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
return rows
|
return rows
|
||||||
}
|
}
|
||||||
|
|
||||||
func header() *ui.Row {
|
func header() *ui.Row {
|
||||||
//cid
|
// cid
|
||||||
c1 := ui.NewPar(" CID")
|
c1 := ui.NewPar(" CID")
|
||||||
c1.Border = false
|
c1.Border = false
|
||||||
c1.Height = 2
|
c1.Height = 2
|
||||||
c1.Width = 20
|
c1.Width = 20
|
||||||
c1.TextFgColor = ui.ColorWhite
|
c1.TextFgColor = ui.ColorWhite
|
||||||
|
|
||||||
//cpu
|
// cpu
|
||||||
c2 := ui.NewPar(" CPU")
|
c2 := ui.NewPar(" CPU")
|
||||||
c2.Border = false
|
c2.Border = false
|
||||||
c2.Height = 2
|
c2.Height = 2
|
||||||
c2.Width = 10
|
c2.Width = 10
|
||||||
c2.TextFgColor = ui.ColorWhite
|
c2.TextFgColor = ui.ColorWhite
|
||||||
|
|
||||||
//mem
|
// mem
|
||||||
c3 := ui.NewPar(" MEM")
|
c3 := ui.NewPar(" MEM")
|
||||||
c3.Border = false
|
c3.Border = false
|
||||||
c3.Height = 2
|
c3.Height = 2
|
||||||
c3.Width = 10
|
c3.Width = 10
|
||||||
c3.TextFgColor = ui.ColorWhite
|
c3.TextFgColor = ui.ColorWhite
|
||||||
|
|
||||||
//misc
|
// net
|
||||||
c4 := ui.NewPar(" MISC")
|
c4 := ui.NewPar(" NET RX/TX")
|
||||||
c4.Border = false
|
c4.Border = false
|
||||||
c4.Height = 2
|
c4.Height = 2
|
||||||
c4.Width = 10
|
c4.Width = 10
|
||||||
|
11
reader.go
11
reader.go
@ -6,6 +6,8 @@ import (
|
|||||||
|
|
||||||
type StatReader struct {
|
type StatReader struct {
|
||||||
CPUUtil int
|
CPUUtil int
|
||||||
|
NetTx int64
|
||||||
|
NetRx int64
|
||||||
MemUsage int64
|
MemUsage int64
|
||||||
MemLimit int64
|
MemLimit int64
|
||||||
//MemPercent int64
|
//MemPercent int64
|
||||||
@ -16,6 +18,7 @@ type StatReader struct {
|
|||||||
func (s *StatReader) Read(stats *docker.Stats) {
|
func (s *StatReader) Read(stats *docker.Stats) {
|
||||||
s.ReadCPU(stats)
|
s.ReadCPU(stats)
|
||||||
s.ReadMem(stats)
|
s.ReadMem(stats)
|
||||||
|
s.ReadNet(stats)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StatReader) ReadCPU(stats *docker.Stats) {
|
func (s *StatReader) ReadCPU(stats *docker.Stats) {
|
||||||
@ -35,3 +38,11 @@ func (s *StatReader) ReadMem(stats *docker.Stats) {
|
|||||||
s.MemLimit = int64(stats.MemoryStats.Limit)
|
s.MemLimit = int64(stats.MemoryStats.Limit)
|
||||||
//s.MemPercent = round((float64(cur) / float64(limit)) * 100)
|
//s.MemPercent = round((float64(cur) / float64(limit)) * 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StatReader) ReadNet(stats *docker.Stats) {
|
||||||
|
s.NetTx, s.NetRx = 0, 0
|
||||||
|
for _, network := range stats.Networks {
|
||||||
|
s.NetTx += int64(network.TxBytes)
|
||||||
|
s.NetRx += int64(network.RxBytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
type Widgets struct {
|
type Widgets struct {
|
||||||
cid *ui.Par
|
cid *ui.Par
|
||||||
cpu *ui.Gauge
|
cpu *ui.Gauge
|
||||||
|
net *ui.Gauge
|
||||||
memory *ui.Gauge
|
memory *ui.Gauge
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,6 +23,10 @@ func (w *Widgets) SetCPU(val int) {
|
|||||||
w.cpu.Percent = val
|
w.cpu.Percent = val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Widgets) SetNet(rx int64, tx int64) {
|
||||||
|
w.net.Label = fmt.Sprintf("%s / %s", byteFormat(rx), byteFormat(tx))
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Widgets) SetMem(val int64, limit int64) {
|
func (w *Widgets) SetMem(val int64, limit int64) {
|
||||||
if val < 5 {
|
if val < 5 {
|
||||||
val = 5
|
val = 5
|
||||||
@ -36,7 +41,7 @@ func NewWidgets(id string) *Widgets {
|
|||||||
cid.Height = 1
|
cid.Height = 1
|
||||||
cid.Width = 20
|
cid.Width = 20
|
||||||
cid.TextFgColor = ui.ColorWhite
|
cid.TextFgColor = ui.ColorWhite
|
||||||
return &Widgets{cid, mkGauge(), mkGauge()}
|
return &Widgets{cid, mkGauge(), mkGauge(), mkGauge()}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mkGauge() *ui.Gauge {
|
func mkGauge() *ui.Gauge {
|
||||||
|
Loading…
Reference in New Issue
Block a user