-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathblkio.go
More file actions
39 lines (35 loc) · 1.18 KB
/
blkio.go
File metadata and controls
39 lines (35 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"fmt"
//log "github.com/Sirupsen/logrus"
"github.com/docker/engine-api/types"
humanize "github.com/dustin/go-humanize"
ui "github.com/gizak/termui"
)
type BlkIOWidget struct {
Views []ui.GridBufferer
Handler func(ui.Event)
}
func NewBlkIOWidget() BlkIOWidget {
servicedOps := ui.NewList()
servicedOps.BorderLabel = "I/O Operations"
servicedOps.PaddingLeft = 1
servicedBytes := ui.NewList()
servicedBytes.BorderLabel = "I/O Bytes"
servicedBytes.PaddingLeft = 1
servicedOps.Height = 5
servicedBytes.Height = 5
return BlkIOWidget{Views: []ui.GridBufferer{servicedOps, servicedBytes}, Handler: func(e ui.Event) {
stats := e.Data.(types.StatsJSON)
opsData := make([]string, len(stats.BlkioStats.IoServicedRecursive))
for idx, element := range stats.BlkioStats.IoServicedRecursive {
opsData[idx] = fmt.Sprintf("%s: %d", element.Op, element.Value)
}
servicedOps.Items = opsData
bytesData := make([]string, len(stats.BlkioStats.IoServiceBytesRecursive))
for idx, element := range stats.BlkioStats.IoServiceBytesRecursive {
bytesData[idx] = fmt.Sprintf("%s: %s", element.Op, humanize.Bytes(element.Value))
}
servicedBytes.Items = bytesData
}}
}