From 8a5531777b5697f7928920972e6a3cce540a1c00 Mon Sep 17 00:00:00 2001 From: Sun Hongliang Date: Tue, 19 Apr 2016 21:59:52 +0800 Subject: [PATCH] show container status of each node in docker info Signed-off-by: Sun Hongliang --- cluster/swarm/cluster.go | 19 ++++++++++++++++++- test/integration/api/info.bats | 5 ++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cluster/swarm/cluster.go b/cluster/swarm/cluster.go index 50c91d93c9..4585ecf60e 100644 --- a/cluster/swarm/cluster.go +++ b/cluster/swarm/cluster.go @@ -865,7 +865,24 @@ func (c *Cluster) Info() [][2]string { info = append(info, [2]string{" " + engineName, engine.Addr}) info = append(info, [2]string{" └ ID", engine.ID}) info = append(info, [2]string{" └ Status", engine.Status()}) - info = append(info, [2]string{" └ Containers", fmt.Sprintf("%d", len(engine.Containers()))}) + + // if engine's status is healthy, show container details of the node + if engine.IsHealthy() { + var paused, running, stopped int = 0, 0, 0 + for _, c := range engine.Containers() { + if c.Info.State.Paused { + paused++ + } else if c.Info.State.Running { + running++ + } else { + stopped++ + } + } + info = append(info, [2]string{" └ Containers", fmt.Sprintf("%d (%d Running, %d Paused, %d Stopped)", len(engine.Containers()), running, paused, stopped)}) + } else { + info = append(info, [2]string{" └ Containers", fmt.Sprintf("%d", len(engine.Containers()))}) + } + info = append(info, [2]string{" └ Reserved CPUs", fmt.Sprintf("%d / %d", engine.UsedCpus(), engine.TotalCpus())}) info = append(info, [2]string{" └ Reserved Memory", fmt.Sprintf("%s / %s", units.BytesSize(float64(engine.UsedMemory())), units.BytesSize(float64(engine.TotalMemory())))}) labels := make([]string, 0, len(engine.Labels)) diff --git a/test/integration/api/info.bats b/test/integration/api/info.bats index c57ba2d33f..8ae5688f2d 100644 --- a/test/integration/api/info.bats +++ b/test/integration/api/info.bats @@ -31,15 +31,18 @@ function teardown() { run docker_swarm info [ "$status" -eq 0 ] [[ "${output}" == *"Running: 1"* ]] + [[ "${output}" == *"Containers: 1 (1 Running, 0 Paused, 0 Stopped)"* ]] docker_swarm pause test run docker_swarm info [ "$status" -eq 0 ] [[ "${output}" == *"Paused: 1"* ]] + [[ "${output}" == *"Containers: 1 (0 Running, 1 Paused, 0 Stopped)"* ]] docker_swarm unpause test docker_swarm kill test run docker_swarm info [ "$status" -eq 0 ] [[ "${output}" == *"Stopped: 1"* ]] -} \ No newline at end of file + [[ "${output}" == *"Containers: 1 (0 Running, 0 Paused, 1 Stopped)"* ]] +}