Browse code

Format output of docker info

Format those info which will only be displayed when daemon is
in debug mode.

Signed-off-by: Hu Keping <hukeping@huawei.com>

Hu Keping authored on 2015/09/19 11:36:10
Showing 4 changed files
... ...
@@ -53,13 +53,13 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
53 53
 
54 54
 	if info.Debug {
55 55
 		fmt.Fprintf(cli.out, "Debug mode (server): %v\n", info.Debug)
56
-		fmt.Fprintf(cli.out, "File Descriptors: %d\n", info.NFd)
57
-		fmt.Fprintf(cli.out, "Goroutines: %d\n", info.NGoroutines)
58
-		fmt.Fprintf(cli.out, "System Time: %s\n", info.SystemTime)
59
-		fmt.Fprintf(cli.out, "EventsListeners: %d\n", info.NEventsListener)
60
-		fmt.Fprintf(cli.out, "Init SHA1: %s\n", info.InitSha1)
61
-		fmt.Fprintf(cli.out, "Init Path: %s\n", info.InitPath)
62
-		fmt.Fprintf(cli.out, "Docker Root Dir: %s\n", info.DockerRootDir)
56
+		fmt.Fprintf(cli.out, " File Descriptors: %d\n", info.NFd)
57
+		fmt.Fprintf(cli.out, " Goroutines: %d\n", info.NGoroutines)
58
+		fmt.Fprintf(cli.out, " System Time: %s\n", info.SystemTime)
59
+		fmt.Fprintf(cli.out, " EventsListeners: %d\n", info.NEventsListener)
60
+		fmt.Fprintf(cli.out, " Init SHA1: %s\n", info.InitSha1)
61
+		fmt.Fprintf(cli.out, " Init Path: %s\n", info.InitPath)
62
+		fmt.Fprintf(cli.out, " Docker Root Dir: %s\n", info.DockerRootDir)
63 63
 	}
64 64
 
65 65
 	ioutils.FprintfIfNotEmpty(cli.out, "Http Proxy: %s\n", info.HTTPProxy)
... ...
@@ -73,7 +73,8 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
73 73
 			fmt.Fprintf(cli.out, "Registry: %v\n", info.IndexServerAddress)
74 74
 		}
75 75
 	}
76
-	// Only output these warnings if the server supports these features
76
+
77
+	// Only output these warnings if the server does not support these features
77 78
 	if h, err := httputils.ParseServerHeader(serverResp.header.Get("Server")); err == nil {
78 79
 		if h.OS != "windows" {
79 80
 			if !info.MemoryLimit {
... ...
@@ -101,9 +102,7 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
101 101
 		}
102 102
 	}
103 103
 
104
-	if info.ExperimentalBuild {
105
-		fmt.Fprintf(cli.out, "Experimental: true\n")
106
-	}
104
+	ioutils.FprintfIfTrue(cli.out, "Experimental: %v\n", info.ExperimentalBuild)
107 105
 
108 106
 	return nil
109 107
 }
... ...
@@ -26,25 +26,26 @@ For example:
26 26
      Root Dir: /var/lib/docker/aufs
27 27
      Backing Filesystem: extfs
28 28
      Dirs: 545
29
+     Dirperm1 Supported: true
29 30
     Execution Driver: native-0.2
30 31
     Logging Driver: json-file
31
-    Kernel Version: 3.13.0-24-generic
32
-    Operating System: Ubuntu 14.04 LTS
33
-    CPUs: 1
34
-    Name: prod-server-42
35
-    ID: 7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS
36
-    Total Memory: 2 GiB
37
-    Debug mode (server): false
38
-    Debug mode (client): true
39
-    File Descriptors: 10
40
-    Goroutines: 9
41
-    System Time: Tue Mar 10 18:38:57 UTC 2015
42
-    EventsListeners: 0
43
-    Init Path: /usr/bin/docker
44
-    Docker Root Dir: /var/lib/docker
45
-    Http Proxy: http://test:test@localhost:8080
46
-    Https Proxy: https://test:test@localhost:8080
47
-    No Proxy: 9.81.1.160
32
+    Kernel Version: 3.19.0-22-generic
33
+    Operating System: Ubuntu 15.04
34
+    CPUs: 24
35
+    Total Memory: 62.86 GiB
36
+    Name: docker
37
+    ID: I54V:OLXT:HVMM:TPKO:JPHQ:CQCD:JNLC:O3BZ:4ZVJ:43XJ:PFHZ:6N2S
38
+    Debug mode (server): true
39
+     File Descriptors: 59
40
+     Goroutines: 159
41
+     System Time: 2015-09-23T14:04:20.699842089+08:00
42
+     EventsListeners: 0
43
+     Init SHA1:
44
+     Init Path: /usr/bin/docker
45
+     Docker Root Dir: /var/lib/docker
46
+     Http Proxy: http://test:test@localhost:8080
47
+     Https Proxy: https://test:test@localhost:8080
48
+    WARNING: No swap limit support
48 49
     Username: svendowideit
49 50
     Registry: [https://index.docker.io/v1/]
50 51
     Labels:
... ...
@@ -185,29 +185,36 @@ on how to query labels set on a container.
185 185
 
186 186
 These labels appear as part of the `docker info` output for the daemon:
187 187
 
188
-    docker -D info
188
+    $ docker -D info
189 189
     Containers: 12
190 190
     Images: 672
191
+    Engine Version: 1.9.0
191 192
     Storage Driver: aufs
192 193
      Root Dir: /var/lib/docker/aufs
193 194
      Backing Filesystem: extfs
194 195
      Dirs: 697
196
+     Dirperm1 Supported: true
195 197
     Execution Driver: native-0.2
196 198
     Logging Driver: json-file
197
-    Kernel Version: 3.13.0-32-generic
198
-    Operating System: Ubuntu 14.04.1 LTS
199
-    CPUs: 1
200
-    Total Memory: 994.1 MiB
201
-    Name: docker.example.com
202
-    ID: RC3P:JTCT:32YS:XYSB:YUBG:VFED:AAJZ:W3YW:76XO:D7NN:TEVU:UCRW
203
-    Debug mode (server): false
204
-    Debug mode (client): true
205
-    File Descriptors: 11
206
-    Goroutines: 14
207
-    EventsListeners: 0
208
-    Init Path: /usr/bin/docker
209
-    Docker Root Dir: /var/lib/docker
199
+    Kernel Version: 3.19.0-22-generic
200
+    Operating System: Ubuntu 15.04
201
+    CPUs: 24
202
+    Total Memory: 62.86 GiB
203
+    Name: docker
204
+    ID: I54V:OLXT:HVMM:TPKO:JPHQ:CQCD:JNLC:O3BZ:4ZVJ:43XJ:PFHZ:6N2S
205
+    Debug mode (server): true
206
+     File Descriptors: 59
207
+     Goroutines: 159
208
+     System Time: 2015-09-23T14:04:20.699842089+08:00
209
+     EventsListeners: 0
210
+     Init SHA1:
211
+     Init Path: /usr/bin/docker
212
+     Docker Root Dir: /var/lib/docker
213
+     Http Proxy: http://test:test@localhost:8080
214
+     Https Proxy: https://test:test@localhost:8080
210 215
     WARNING: No swap limit support
216
+    Username: svendowideit
217
+    Registry: [https://index.docker.io/v1/]
211 218
     Labels:
212 219
      com.example.environment=production
213 220
      com.example.storage=ssd
... ...
@@ -12,3 +12,11 @@ func FprintfIfNotEmpty(w io.Writer, format, value string) (int, error) {
12 12
 	}
13 13
 	return 0, nil
14 14
 }
15
+
16
+// FprintfIfTrue prints the boolean value if it's true
17
+func FprintfIfTrue(w io.Writer, format string, ok bool) (int, error) {
18
+	if ok {
19
+		return fmt.Fprintf(w, format, ok)
20
+	}
21
+	return 0, nil
22
+}