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:
Brian Goff 2015-08-20 07:53:38 -04:00
commit 44465098cb
2 changed files with 17 additions and 2 deletions

View File

@ -211,9 +211,9 @@ func calculateBlockIO(blkio types.BlkioStats) (blkRead uint64, blkWrite uint64)
for _, bioEntry := range blkio.IoServiceBytesRecursive {
switch strings.ToLower(bioEntry.Op) {
case "read":
blkRead = bioEntry.Value
blkRead = blkRead + bioEntry.Value
case "write":
blkWrite = bioEntry.Value
blkWrite = blkWrite + bioEntry.Value
}
}
return

View File

@ -4,6 +4,8 @@ import (
"bytes"
"sync"
"testing"
"github.com/docker/docker/api/types"
)
func TestDisplay(t *testing.T) {
@ -29,3 +31,16 @@ func TestDisplay(t *testing.T) {
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)
}
}