From 211449a1cad317e80610e40c9d8c88df35cae60d Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Thu, 20 Aug 2015 11:46:21 +0800 Subject: [PATCH] Fix docker stats show blkio when there are multiple block devices. Signed-off-by: Lei Jiang --- api/client/stats.go | 4 ++-- api/client/stats_unit_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/api/client/stats.go b/api/client/stats.go index 84f323ec29..b79d3a5f3f 100644 --- a/api/client/stats.go +++ b/api/client/stats.go @@ -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 diff --git a/api/client/stats_unit_test.go b/api/client/stats_unit_test.go index 41f3743e05..301e0a6782 100644 --- a/api/client/stats_unit_test.go +++ b/api/client/stats_unit_test.go @@ -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) + } +}