Ver código fonte

Fix docker stats show blkio when there are multiple block devices.

Signed-off-by: Lei Jiang <leijitang@huawei.com>
Lei Jitang 10 anos atrás
pai
commit
211449a1ca
2 arquivos alterados com 17 adições e 2 exclusões
  1. 2 2
      api/client/stats.go
  2. 15 0
      api/client/stats_unit_test.go

+ 2 - 2
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

+ 15 - 0
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)
+	}
+}