mirror of
https://github.com/bcicen/ctop.git
synced 2026-01-21 05:36:42 +08:00
add pids, IO stat
This commit is contained in:
51
cwidgets/expanded/io.go
Normal file
51
cwidgets/expanded/io.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package expanded
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/bcicen/ctop/cwidgets"
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
type IO struct {
|
||||
*ui.Sparklines
|
||||
readHist *DiffHist
|
||||
writeHist *DiffHist
|
||||
}
|
||||
|
||||
func NewIO() *IO {
|
||||
io := &IO{ui.NewSparklines(), NewDiffHist(60), NewDiffHist(60)}
|
||||
io.BorderLabel = "IO"
|
||||
io.Height = 6
|
||||
io.Width = colWidth[0]
|
||||
io.X = 0
|
||||
io.Y = 24
|
||||
|
||||
read := ui.NewSparkline()
|
||||
read.Title = "read"
|
||||
read.Height = 1
|
||||
read.Data = io.readHist.Data
|
||||
read.LineColor = ui.ColorGreen
|
||||
|
||||
write := ui.NewSparkline()
|
||||
write.Title = "write"
|
||||
write.Height = 1
|
||||
write.Data = io.writeHist.Data
|
||||
write.LineColor = ui.ColorYellow
|
||||
|
||||
io.Lines = []ui.Sparkline{read, write}
|
||||
return io
|
||||
}
|
||||
|
||||
func (w *IO) Update(read int64, write int64) {
|
||||
var rate string
|
||||
|
||||
w.readHist.Append(int(read))
|
||||
rate = strings.ToLower(cwidgets.ByteFormatInt(w.readHist.Val))
|
||||
w.Lines[0].Title = fmt.Sprintf("read [%s/s]", rate)
|
||||
|
||||
w.writeHist.Append(int(write))
|
||||
rate = strings.ToLower(cwidgets.ByteFormatInt(w.writeHist.Val))
|
||||
w.Lines[1].Title = fmt.Sprintf("write [%s/s]", rate)
|
||||
}
|
||||
@@ -17,6 +17,7 @@ type Expanded struct {
|
||||
Net *Net
|
||||
Cpu *Cpu
|
||||
Mem *Mem
|
||||
IO *IO
|
||||
Width int
|
||||
}
|
||||
|
||||
@@ -29,6 +30,7 @@ func NewExpanded(id string) *Expanded {
|
||||
Net: NewNet(),
|
||||
Cpu: NewCpu(),
|
||||
Mem: NewMem(),
|
||||
IO: NewIO(),
|
||||
Width: ui.TermWidth(),
|
||||
}
|
||||
}
|
||||
@@ -45,6 +47,7 @@ func (e *Expanded) SetMetrics(m metrics.Metrics) {
|
||||
e.Cpu.Update(m.CPUUtil)
|
||||
e.Net.Update(m.NetRx, m.NetTx)
|
||||
e.Mem.Update(int(m.MemUsage), int(m.MemLimit))
|
||||
e.IO.Update(m.IOBytesRead, m.IOBytesWrite)
|
||||
}
|
||||
|
||||
func (e *Expanded) Align() {
|
||||
@@ -74,6 +77,7 @@ func (e *Expanded) Buffer() ui.Buffer {
|
||||
buf.Merge(e.Cpu.Buffer())
|
||||
buf.Merge(e.Mem.Buffer())
|
||||
buf.Merge(e.Net.Buffer())
|
||||
buf.Merge(e.IO.Buffer())
|
||||
return buf
|
||||
}
|
||||
|
||||
@@ -83,6 +87,7 @@ func (e *Expanded) all() []ui.GridBufferer {
|
||||
e.Cpu,
|
||||
e.Mem,
|
||||
e.Net,
|
||||
e.IO,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user