From 1bbe8463feee61c65e445f20761e214f0d92efa3 Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Mon, 26 Dec 2016 17:57:55 +0000 Subject: [PATCH] add net rx/tx column --- container.go | 1 + grid.go | 11 ++++++----- reader.go | 11 +++++++++++ widgets.go | 7 ++++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/container.go b/container.go index 455579b..60a462d 100644 --- a/container.go +++ b/container.go @@ -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) } }() diff --git a/grid.go b/grid.go index af53054..d7fc6fb 100644 --- a/grid.go +++ b/grid.go @@ -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 diff --git a/reader.go b/reader.go index fcc1967..3f4c435 100644 --- a/reader.go +++ b/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) + } +} diff --git a/widgets.go b/widgets.go index acd3cea..6a1e6e0 100644 --- a/widgets.go +++ b/widgets.go @@ -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 {