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.widgets.SetCPU(c.reader.CPUUtil)
|
||||
c.widgets.SetMem(c.reader.MemUsage, c.reader.MemLimit)
|
||||
c.widgets.SetNet(c.reader.NetRx, c.reader.NetTx)
|
||||
}
|
||||
}()
|
||||
|
||||
|
5
grid.go
5
grid.go
@ -31,6 +31,7 @@ func (g *Grid) Rows() (rows []*ui.Row) {
|
||||
ui.NewCol(1, 0, c.widgets.cid),
|
||||
ui.NewCol(2, 0, c.widgets.cpu),
|
||||
ui.NewCol(2, 0, c.widgets.memory),
|
||||
ui.NewCol(2, 0, c.widgets.net),
|
||||
))
|
||||
}
|
||||
return rows
|
||||
@ -58,8 +59,8 @@ func header() *ui.Row {
|
||||
c3.Width = 10
|
||||
c3.TextFgColor = ui.ColorWhite
|
||||
|
||||
//misc
|
||||
c4 := ui.NewPar(" MISC")
|
||||
// net
|
||||
c4 := ui.NewPar(" NET RX/TX")
|
||||
c4.Border = false
|
||||
c4.Height = 2
|
||||
c4.Width = 10
|
||||
|
11
reader.go
11
reader.go
@ -6,6 +6,8 @@ import (
|
||||
|
||||
type StatReader struct {
|
||||
CPUUtil int
|
||||
NetTx int64
|
||||
NetRx int64
|
||||
MemUsage int64
|
||||
MemLimit int64
|
||||
//MemPercent int64
|
||||
@ -16,6 +18,7 @@ type StatReader struct {
|
||||
func (s *StatReader) Read(stats *docker.Stats) {
|
||||
s.ReadCPU(stats)
|
||||
s.ReadMem(stats)
|
||||
s.ReadNet(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.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 {
|
||||
cid *ui.Par
|
||||
cpu *ui.Gauge
|
||||
net *ui.Gauge
|
||||
memory *ui.Gauge
|
||||
}
|
||||
|
||||
@ -22,6 +23,10 @@ func (w *Widgets) SetCPU(val int) {
|
||||
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) {
|
||||
if val < 5 {
|
||||
val = 5
|
||||
@ -36,7 +41,7 @@ func NewWidgets(id string) *Widgets {
|
||||
cid.Height = 1
|
||||
cid.Width = 20
|
||||
cid.TextFgColor = ui.ColorWhite
|
||||
return &Widgets{cid, mkGauge(), mkGauge()}
|
||||
return &Widgets{cid, mkGauge(), mkGauge(), mkGauge()}
|
||||
}
|
||||
|
||||
func mkGauge() *ui.Gauge {
|
||||
|
Loading…
Reference in New Issue
Block a user