change memory usage display

using standard unix postfixes add unit test for display
also change doc for memory usage display change
for example GiB will be GB

Signed-off-by: Sun Jianbo <wonderflow@zju.edu.cn>
This commit is contained in:
jianbosun 2015-04-08 12:25:41 +08:00
parent e3c1cc8d77
commit d6d8f45b04
4 changed files with 33 additions and 4 deletions

View File

@ -99,9 +99,9 @@ func (s *containerStats) Display(w io.Writer) error {
fmt.Fprintf(w, "%s\t%.2f%%\t%s/%s\t%.2f%%\t%s/%s\n",
s.Name,
s.CPUPercentage,
units.BytesSize(s.Memory), units.BytesSize(s.MemoryLimit),
units.HumanSize(s.Memory), units.HumanSize(s.MemoryLimit),
s.MemoryPercentage,
units.BytesSize(s.NetworkRx), units.BytesSize(s.NetworkTx))
units.HumanSize(s.NetworkRx), units.HumanSize(s.NetworkTx))
return nil
}

View File

@ -0,0 +1,29 @@
package client
import (
"bytes"
"sync"
"testing"
)
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,
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%\t104.9 MB/2.147 GB\t4.88%\t104.9 MB/838.9 MB\n"
if got != want {
t.Fatalf("c.Display() = %q, want %q", got, want)
}
}

View File

@ -24,5 +24,5 @@ Run **docker stats** with multiple containers.
$ docker stats redis1 redis2
CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O
redis1 0.07% 796 KiB/64 MiB 1.21% 788 B/648 B
redis2 0.07% 2.746 MiB/64 MiB 4.29% 1.266 KiB/648 B
redis2 0.07% 2.746 MB/64 MB 4.29% 1.266 KB/648 B

View File

@ -2336,7 +2336,7 @@ Running `docker stats` on multiple containers
$ docker stats redis1 redis2
CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O
redis1 0.07% 796 KiB/64 MiB 1.21% 788 B/648 B
redis2 0.07% 2.746 MiB/64 MiB 4.29% 1.266 KiB/648 B
redis2 0.07% 2.746 MB/64 MB 4.29% 1.266 KB/648 B
The `docker stats` command will only return a live stream of data for running