зеркало из https://github.com/microsoft/docker.git
Docker stats: display Block IO stats
Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
This commit is contained in:
Родитель
468bc7d819
Коммит
6a4ac63aaa
|
@ -25,6 +25,8 @@ type containerStats struct {
|
|||
MemoryPercentage float64
|
||||
NetworkRx float64
|
||||
NetworkTx float64
|
||||
BlockRead float64
|
||||
BlockWrite float64
|
||||
mu sync.RWMutex
|
||||
err error
|
||||
}
|
||||
|
@ -66,6 +68,7 @@ func (s *containerStats) Collect(cli *DockerCli, streamStats bool) {
|
|||
previousCPU = v.PreCpuStats.CpuUsage.TotalUsage
|
||||
previousSystem = v.PreCpuStats.SystemUsage
|
||||
cpuPercent = calculateCPUPercent(previousCPU, previousSystem, v)
|
||||
blkRead, blkWrite := calculateBlockIO(v.BlkioStats)
|
||||
s.mu.Lock()
|
||||
s.CPUPercentage = cpuPercent
|
||||
s.Memory = float64(v.MemoryStats.Usage)
|
||||
|
@ -73,6 +76,8 @@ func (s *containerStats) Collect(cli *DockerCli, streamStats bool) {
|
|||
s.MemoryPercentage = memPercent
|
||||
s.NetworkRx = float64(v.Network.RxBytes)
|
||||
s.NetworkTx = float64(v.Network.TxBytes)
|
||||
s.BlockRead = float64(blkRead)
|
||||
s.BlockWrite = float64(blkWrite)
|
||||
s.mu.Unlock()
|
||||
u <- nil
|
||||
if !streamStats {
|
||||
|
@ -110,12 +115,13 @@ func (s *containerStats) Display(w io.Writer) error {
|
|||
if s.err != nil {
|
||||
return s.err
|
||||
}
|
||||
fmt.Fprintf(w, "%s\t%.2f%%\t%s / %s\t%.2f%%\t%s / %s\n",
|
||||
fmt.Fprintf(w, "%s\t%.2f%%\t%s / %s\t%.2f%%\t%s / %s\t%s / %s\n",
|
||||
s.Name,
|
||||
s.CPUPercentage,
|
||||
units.HumanSize(s.Memory), units.HumanSize(s.MemoryLimit),
|
||||
s.MemoryPercentage,
|
||||
units.HumanSize(s.NetworkRx), units.HumanSize(s.NetworkTx))
|
||||
units.HumanSize(s.NetworkRx), units.HumanSize(s.NetworkTx),
|
||||
units.HumanSize(s.BlockRead), units.HumanSize(s.BlockWrite))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -142,7 +148,7 @@ func (cli *DockerCli) CmdStats(args ...string) error {
|
|||
fmt.Fprint(cli.out, "\033[2J")
|
||||
fmt.Fprint(cli.out, "\033[H")
|
||||
}
|
||||
io.WriteString(w, "CONTAINER\tCPU %\tMEM USAGE / LIMIT\tMEM %\tNET I/O\n")
|
||||
io.WriteString(w, "CONTAINER\tCPU %\tMEM USAGE / LIMIT\tMEM %\tNET I/O\tBLOCK I/O\n")
|
||||
}
|
||||
for _, n := range names {
|
||||
s := &containerStats{Name: n}
|
||||
|
@ -200,3 +206,15 @@ func calculateCPUPercent(previousCPU, previousSystem uint64, v *types.Stats) flo
|
|||
}
|
||||
return cpuPercent
|
||||
}
|
||||
|
||||
func calculateBlockIO(blkio types.BlkioStats) (blkRead uint64, blkWrite uint64) {
|
||||
for _, bioEntry := range blkio.IoServiceBytesRecursive {
|
||||
switch strings.ToLower(bioEntry.Op) {
|
||||
case "read":
|
||||
blkRead = bioEntry.Value
|
||||
case "write":
|
||||
blkWrite = bioEntry.Value
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ func TestDisplay(t *testing.T) {
|
|||
MemoryPercentage: 100.0 / 2048.0 * 100.0,
|
||||
NetworkRx: 100 * 1024 * 1024,
|
||||
NetworkTx: 800 * 1024 * 1024,
|
||||
BlockRead: 100 * 1024 * 1024,
|
||||
BlockWrite: 800 * 1024 * 1024,
|
||||
mu: sync.RWMutex{},
|
||||
}
|
||||
var b bytes.Buffer
|
||||
|
@ -22,7 +24,7 @@ func TestDisplay(t *testing.T) {
|
|||
t.Fatalf("c.Display() gave error: %s", err)
|
||||
}
|
||||
got := b.String()
|
||||
want := "app\t30.00%\t104.9 MB / 2.147 GB\t4.88%\t104.9 MB / 838.9 MB\n"
|
||||
want := "app\t30.00%\t104.9 MB / 2.147 GB\t4.88%\t104.9 MB / 838.9 MB\t104.9 MB / 838.9 MB\n"
|
||||
if got != want {
|
||||
t.Fatalf("c.Display() = %q, want %q", got, want)
|
||||
}
|
||||
|
|
|
@ -21,9 +21,9 @@ and network IO metrics.
|
|||
The following is a sample output from the `docker stats` command
|
||||
|
||||
$ docker stats redis1 redis2
|
||||
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O
|
||||
redis1 0.07% 796 KB / 64 MB 1.21% 788 B / 648 B
|
||||
redis2 0.07% 2.746 MB / 64 MB 4.29% 1.266 KB / 648 B
|
||||
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O
|
||||
redis1 0.07% 796 KB / 64 MB 1.21% 788 B / 648 B 3.568 MB / 512 KB
|
||||
redis2 0.07% 2.746 MB / 64 MB 4.29% 1.266 KB / 648 B 12.4 MB / 0 B
|
||||
|
||||
|
||||
The [docker stats](/reference/commandline/stats/) reference page has
|
||||
|
|
|
@ -21,9 +21,9 @@ weight=1
|
|||
Running `docker stats` on multiple containers
|
||||
|
||||
$ docker stats redis1 redis2
|
||||
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O
|
||||
redis1 0.07% 796 KB / 64 MB 1.21% 788 B / 648 B
|
||||
redis2 0.07% 2.746 MB / 64 MB 4.29% 1.266 KB / 648 B
|
||||
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O
|
||||
redis1 0.07% 796 KB / 64 MB 1.21% 788 B / 648 B 3.568 MB / 512 KB
|
||||
redis2 0.07% 2.746 MB / 64 MB 4.29% 1.266 KB / 648 B 12.4 MB / 0 B
|
||||
|
||||
|
||||
The `docker stats` command will only return a live stream of data for running
|
||||
|
|
|
@ -25,6 +25,6 @@ Display a live stream of one or more containers' resource usage statistics
|
|||
Run **docker stats** with multiple containers.
|
||||
|
||||
$ docker stats redis1 redis2
|
||||
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O
|
||||
redis1 0.07% 796 KB / 64 MB 1.21% 788 B / 648 B
|
||||
redis2 0.07% 2.746 MB / 64 MB 4.29% 1.266 KB / 648 B
|
||||
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O
|
||||
redis1 0.07% 796 KB / 64 MB 1.21% 788 B / 648 B 3.568 MB / 512 KB
|
||||
redis2 0.07% 2.746 MB / 64 MB 4.29% 1.266 KB / 648 B 12.4 MB / 0 B
|
||||
|
|
Загрузка…
Ссылка в новой задаче