mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
0e3846e280
This fix tries to fix the discrepancy between `docker stats` and `docker run` where `docker run` uses RAMInBytes for all memory related inputs but `docker stats` uses HumanSize for all memory related outputs. To be consistent, `docker stats` needs to use BytesSize for all memory related outputs to conform to RAMInBytes in `docker run`. This fix addresses this issue. As BytesSize is used, the test cases needs to be adjusted to match `KiB/MiB/GiB` instead of `KB/MB/GB`. The documentation has also been updated. This fix fixes #21765. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package client
|
|
|
|
import (
|
|
"bytes"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/docker/engine-api/types"
|
|
)
|
|
|
|
func TestDisplay(t *testing.T) {
|
|
c := &containerStats{
|
|
Name: "app",
|
|
CPUPercentage: 30.0,
|
|
Memory: 100 * 1024 * 1024.0,
|
|
MemoryLimit: 2048 * 1024 * 1024.0,
|
|
MemoryPercentage: 100.0 / 2048.0 * 100.0,
|
|
NetworkRx: 100 * 1024 * 1024,
|
|
NetworkTx: 800 * 1024 * 1024,
|
|
BlockRead: 100 * 1024 * 1024,
|
|
BlockWrite: 800 * 1024 * 1024,
|
|
PidsCurrent: 1,
|
|
mu: sync.RWMutex{},
|
|
}
|
|
var b bytes.Buffer
|
|
if err := c.Display(&b); err != nil {
|
|
t.Fatalf("c.Display() gave error: %s", err)
|
|
}
|
|
got := b.String()
|
|
want := "app\t30.00%\t100 MiB / 2 GiB\t4.88%\t104.9 MB / 838.9 MB\t104.9 MB / 838.9 MB\t1\n"
|
|
if 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)
|
|
}
|
|
}
|