Browse code

Merge pull request #19249 from calavera/carry_17414

[Carry 17414] Added additional container information to "docker info".

Antonio Murdaca authored on 2016/01/13 18:42:22
Showing 10 changed files
... ...
@@ -25,6 +25,9 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
25 25
 	}
26 26
 
27 27
 	fmt.Fprintf(cli.out, "Containers: %d\n", info.Containers)
28
+	fmt.Fprintf(cli.out, " Running: %d\n", info.ContainersRunning)
29
+	fmt.Fprintf(cli.out, " Paused: %d\n", info.ContainersPaused)
30
+	fmt.Fprintf(cli.out, " Stopped: %d\n", info.ContainersStopped)
28 31
 	fmt.Fprintf(cli.out, "Images: %d\n", info.Images)
29 32
 	ioutils.FprintfIfNotEmpty(cli.out, "Server Version: %s\n", info.ServerVersion)
30 33
 	ioutils.FprintfIfNotEmpty(cli.out, "Storage Driver: %s\n", info.Driver)
... ...
@@ -54,9 +54,24 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
54 54
 	initPath := utils.DockerInitPath("")
55 55
 	sysInfo := sysinfo.New(true)
56 56
 
57
+	var cRunning, cPaused, cStopped int
58
+	for _, c := range daemon.List() {
59
+		switch c.StateString() {
60
+		case "paused":
61
+			cPaused++
62
+		case "running":
63
+			cRunning++
64
+		default:
65
+			cStopped++
66
+		}
67
+	}
68
+
57 69
 	v := &types.Info{
58 70
 		ID:                 daemon.ID,
59 71
 		Containers:         len(daemon.List()),
72
+		ContainersRunning:  cRunning,
73
+		ContainersPaused:   cPaused,
74
+		ContainersStopped:  cStopped,
60 75
 		Images:             len(daemon.imageStore.Map()),
61 76
 		Driver:             daemon.GraphDriverName(),
62 77
 		DriverStatus:       daemon.layerStore.DriverStatus(),
... ...
@@ -113,6 +113,7 @@ This section lists each version from latest to oldest.  Each listing includes a
113 113
 * `GET /networks` now supports filtering by `name`, `id` and `type`.
114 114
 * `POST /containers/create` now allows you to set the static IPv4 and/or IPv6 address for the container.
115 115
 * `POST /networks/(id)/connect` now allows you to set the static IPv4 and/or IPv6 address for the container.
116
+* `GET /info` now includes the number of containers running, stopped, and paused.
116 117
 
117 118
 ### v1.21 API changes
118 119
 
... ...
@@ -2081,6 +2081,9 @@ Display system-wide information
2081 2081
     {
2082 2082
         "Architecture": "x86_64",
2083 2083
         "Containers": 11,
2084
+        "ContainersRunning": 7,
2085
+        "ContainersStopped": 3,
2086
+        "ContainersPaused": 1,
2084 2087
         "CpuCfsPeriod": true,
2085 2088
         "CpuCfsQuota": true,
2086 2089
         "Debug": false,
... ...
@@ -21,6 +21,9 @@ For example:
21 21
 
22 22
     $ docker -D info
23 23
     Containers: 14
24
+     Running: 3
25
+     Paused: 1
26
+     Stopped: 10
24 27
     Images: 52
25 28
     Server Version: 1.9.0
26 29
     Storage Driver: aufs
... ...
@@ -192,6 +192,9 @@ These labels appear as part of the `docker info` output for the daemon:
192 192
 
193 193
     $ docker -D info
194 194
     Containers: 12
195
+     Running: 5
196
+     Paused: 2
197
+     Stopped: 5
195 198
     Images: 672
196 199
     Server Version: 1.9.0
197 200
     Storage Driver: aufs
... ...
@@ -28,6 +28,7 @@ type DockerSuite struct {
28 28
 }
29 29
 
30 30
 func (s *DockerSuite) TearDownTest(c *check.C) {
31
+	unpauseAllContainers()
31 32
 	deleteAllContainers()
32 33
 	deleteAllImages()
33 34
 	deleteAllVolumes()
... ...
@@ -18,6 +18,9 @@ func (s *DockerSuite) TestInfoApi(c *check.C) {
18 18
 	stringsToCheck := []string{
19 19
 		"ID",
20 20
 		"Containers",
21
+		"ContainersRunning",
22
+		"ContainersPaused",
23
+		"ContainersStopped",
21 24
 		"Images",
22 25
 		"ExecutionDriver",
23 26
 		"LoggingDriver",
... ...
@@ -3,6 +3,7 @@ package main
3 3
 import (
4 4
 	"fmt"
5 5
 	"net"
6
+	"strings"
6 7
 
7 8
 	"github.com/docker/docker/pkg/integration/checker"
8 9
 	"github.com/docker/docker/utils"
... ...
@@ -17,6 +18,9 @@ func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) {
17 17
 	stringsToCheck := []string{
18 18
 		"ID:",
19 19
 		"Containers:",
20
+		" Running:",
21
+		" Paused:",
22
+		" Stopped:",
20 23
 		"Images:",
21 24
 		"Execution Driver:",
22 25
 		"OSType:",
... ...
@@ -101,3 +105,44 @@ func (s *DockerSuite) TestInfoDiscoveryAdvertiseInterfaceName(c *check.C) {
101 101
 	c.Assert(out, checker.Contains, fmt.Sprintf("Cluster store: %s\n", discoveryBackend))
102 102
 	c.Assert(out, checker.Contains, fmt.Sprintf("Cluster advertise: %s:2375\n", ip.String()))
103 103
 }
104
+
105
+func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *check.C) {
106
+	testRequires(c, DaemonIsLinux)
107
+
108
+	dockerCmd(c, "run", "-d", "busybox", "top")
109
+	out, _ := dockerCmd(c, "info")
110
+	c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
111
+	c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 1))
112
+	c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 0))
113
+	c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 0))
114
+}
115
+
116
+func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *check.C) {
117
+	testRequires(c, DaemonIsLinux)
118
+
119
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
120
+	cleanedContainerID := strings.TrimSpace(out)
121
+
122
+	dockerCmd(c, "pause", cleanedContainerID)
123
+
124
+	out, _ = dockerCmd(c, "info")
125
+	c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
126
+	c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 0))
127
+	c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 1))
128
+	c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 0))
129
+}
130
+
131
+func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *check.C) {
132
+	testRequires(c, DaemonIsLinux)
133
+
134
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
135
+	cleanedContainerID := strings.TrimSpace(out)
136
+
137
+	dockerCmd(c, "stop", cleanedContainerID)
138
+
139
+	out, _ = dockerCmd(c, "info")
140
+	c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
141
+	c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 0))
142
+	c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 0))
143
+	c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 1))
144
+}
... ...
@@ -32,6 +32,9 @@ Here is a sample output:
32 32
 
33 33
     # docker info
34 34
     Containers: 14
35
+     Running: 3
36
+     Paused: 1
37
+     Stopped: 10
35 38
     Images: 52
36 39
     Server Version: 1.9.0
37 40
     Storage Driver: aufs