ctop/cwidgets/single/io.go

52 lines
1.0 KiB
Go
Raw Normal View History

2017-08-05 11:28:20 +00:00
package single
2017-03-12 01:35:40 +00:00
import (
"fmt"
"strings"
"github.com/bcicen/ctop/cwidgets"
ui "github.com/gizak/termui"
)
type IO struct {
*ui.Sparklines
2017-03-12 05:31:12 +00:00
readHist *DiffHist
2017-03-12 01:35:40 +00:00
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()
2017-03-12 05:31:12 +00:00
read.Title = "READ"
2017-03-12 01:35:40 +00:00
read.Height = 1
read.Data = io.readHist.Data
read.LineColor = ui.ColorGreen
write := ui.NewSparkline()
2017-03-12 05:31:12 +00:00
write.Title = "WRITE"
2017-03-12 01:35:40 +00:00
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.ByteFormatShort(w.readHist.Val))
2017-03-12 01:35:40 +00:00
w.Lines[0].Title = fmt.Sprintf("read [%s/s]", rate)
w.writeHist.Append(int(write))
rate = strings.ToLower(cwidgets.ByteFormatShort(w.writeHist.Val))
2017-03-12 01:35:40 +00:00
w.Lines[1].Title = fmt.Sprintf("write [%s/s]", rate)
}