add net rx/tx column

This commit is contained in:
Bradley Cicenas 2016-12-26 17:57:55 +00:00
parent e5e84ee206
commit 1bbe8463fe
4 changed files with 24 additions and 6 deletions

View File

@ -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)
}
}()

11
grid.go
View File

@ -31,35 +31,36 @@ 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
}
func header() *ui.Row {
//cid
// cid
c1 := ui.NewPar(" CID")
c1.Border = false
c1.Height = 2
c1.Width = 20
c1.TextFgColor = ui.ColorWhite
//cpu
// cpu
c2 := ui.NewPar(" CPU")
c2.Border = false
c2.Height = 2
c2.Width = 10
c2.TextFgColor = ui.ColorWhite
//mem
// mem
c3 := ui.NewPar(" MEM")
c3.Border = false
c3.Height = 2
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

View File

@ -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)
}
}

View File

@ -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 {