mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #15661 from coolljt0725/fix_docker_stats_show_read_blkio
Fix docker stats show blkio when there are multiple block device
This commit is contained in:
commit
44465098cb
2 changed files with 17 additions and 2 deletions
|
@ -211,9 +211,9 @@ func calculateBlockIO(blkio types.BlkioStats) (blkRead uint64, blkWrite uint64)
|
||||||
for _, bioEntry := range blkio.IoServiceBytesRecursive {
|
for _, bioEntry := range blkio.IoServiceBytesRecursive {
|
||||||
switch strings.ToLower(bioEntry.Op) {
|
switch strings.ToLower(bioEntry.Op) {
|
||||||
case "read":
|
case "read":
|
||||||
blkRead = bioEntry.Value
|
blkRead = blkRead + bioEntry.Value
|
||||||
case "write":
|
case "write":
|
||||||
blkWrite = bioEntry.Value
|
blkWrite = blkWrite + bioEntry.Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDisplay(t *testing.T) {
|
func TestDisplay(t *testing.T) {
|
||||||
|
@ -29,3 +31,16 @@ func TestDisplay(t *testing.T) {
|
||||||
t.Fatalf("c.Display() = %q, want %q", got, want)
|
t.Fatalf("c.Display() = %q, want %q", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCalculBlockIO(t *testing.T) {
|
||||||
|
blkio := types.BlkioStats{
|
||||||
|
IoServiceBytesRecursive: []types.BlkioStatEntry{{8, 0, "read", 1234}, {8, 1, "read", 4567}, {8, 0, "write", 123}, {8, 1, "write", 456}},
|
||||||
|
}
|
||||||
|
blkRead, blkWrite := calculateBlockIO(blkio)
|
||||||
|
if blkRead != 5801 {
|
||||||
|
t.Fatalf("blkRead = %d, want 5801", blkRead)
|
||||||
|
}
|
||||||
|
if blkWrite != 579 {
|
||||||
|
t.Fatalf("blkWrite = %d, want 579", blkWrite)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue