Browse code

Print devicemapper status details in docker info

This adds a generic Status call in the Driver api and
implements if for the devicemapper backend.

The status is an array of key/value strings rather than a map so that
we can guarantee some static order of the docker info output.

Alexander Larsson authored on 2013/11/15 19:04:02
Showing 7 changed files
... ...
@@ -52,16 +52,17 @@ type APIInfo struct {
52 52
 	Debug              bool
53 53
 	Containers         int
54 54
 	Images             int
55
-	Driver             string `json:",omitempty"`
56
-	NFd                int    `json:",omitempty"`
57
-	NGoroutines        int    `json:",omitempty"`
58
-	MemoryLimit        bool   `json:",omitempty"`
59
-	SwapLimit          bool   `json:",omitempty"`
60
-	IPv4Forwarding     bool   `json:",omitempty"`
61
-	LXCVersion         string `json:",omitempty"`
62
-	NEventsListener    int    `json:",omitempty"`
63
-	KernelVersion      string `json:",omitempty"`
64
-	IndexServerAddress string `json:",omitempty"`
55
+	Driver             string      `json:",omitempty"`
56
+	DriverStatus       [][2]string `json:",omitempty"`
57
+	NFd                int         `json:",omitempty"`
58
+	NGoroutines        int         `json:",omitempty"`
59
+	MemoryLimit        bool        `json:",omitempty"`
60
+	SwapLimit          bool        `json:",omitempty"`
61
+	IPv4Forwarding     bool        `json:",omitempty"`
62
+	LXCVersion         string      `json:",omitempty"`
63
+	NEventsListener    int         `json:",omitempty"`
64
+	KernelVersion      string      `json:",omitempty"`
65
+	IndexServerAddress string      `json:",omitempty"`
65 66
 }
66 67
 
67 68
 type APITop struct {
... ...
@@ -103,6 +103,10 @@ func (a *AufsDriver) String() string {
103 103
 	return "aufs"
104 104
 }
105 105
 
106
+func (d *AufsDriver) Status() [][2]string {
107
+	return nil
108
+}
109
+
106 110
 // Three folders are created for each id
107 111
 // mnt, layers, and diff
108 112
 func (a *AufsDriver) Create(id, parent string) error {
... ...
@@ -461,6 +461,9 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
461 461
 	fmt.Fprintf(cli.out, "Containers: %d\n", out.Containers)
462 462
 	fmt.Fprintf(cli.out, "Images: %d\n", out.Images)
463 463
 	fmt.Fprintf(cli.out, "Driver: %s\n", out.Driver)
464
+	for _, pair := range out.DriverStatus {
465
+		fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1])
466
+	}
464 467
 	if out.Debug || os.Getenv("DEBUG") != "" {
465 468
 		fmt.Fprintf(cli.out, "Debug mode (server): %v\n", out.Debug)
466 469
 		fmt.Fprintf(cli.out, "Debug mode (client): %v\n", os.Getenv("DEBUG") != "")
... ...
@@ -37,6 +37,21 @@ func (d *Driver) String() string {
37 37
 	return "devicemapper"
38 38
 }
39 39
 
40
+func (d *Driver) Status() [][2]string {
41
+	s := d.DeviceSet.Status()
42
+
43
+	status := [][2]string{
44
+		{"Pool Name", s.PoolName},
45
+		{"Data file", s.DataLoopback},
46
+		{"Metadata file", s.MetadataLoopback},
47
+		{"Data Space Used", fmt.Sprintf("%.1f Mb", float64(s.Data.Used)/(1024*1024))},
48
+		{"Data Space Total", fmt.Sprintf("%.1f Mb", float64(s.Data.Total)/(1024*1024))},
49
+		{"Metadata Space Used", fmt.Sprintf("%.1f Mb", float64(s.Metadata.Used)/(1024*1024))},
50
+		{"Metadata Space Total", fmt.Sprintf("%.1f Mb", float64(s.Metadata.Total)/(1024*1024))},
51
+	}
52
+	return status
53
+}
54
+
40 55
 func (d *Driver) Cleanup() error {
41 56
 	return d.DeviceSet.Shutdown()
42 57
 }
... ...
@@ -19,6 +19,8 @@ type Driver interface {
19 19
 	Get(id string) (dir string, err error)
20 20
 	Size(id string) (bytes int64, err error)
21 21
 
22
+	Status() [][2]string
23
+
22 24
 	Cleanup() error
23 25
 }
24 26
 
... ...
@@ -27,6 +27,10 @@ func (d *Driver) String() string {
27 27
 	return "dummy"
28 28
 }
29 29
 
30
+func (d *Driver) Status() [][2]string {
31
+	return nil
32
+}
33
+
30 34
 func (d *Driver) Cleanup() error {
31 35
 	return nil
32 36
 }
... ...
@@ -376,6 +376,7 @@ func (srv *Server) DockerInfo() *APIInfo {
376 376
 		Containers:         len(srv.runtime.List()),
377 377
 		Images:             imgcount,
378 378
 		Driver:             srv.runtime.driver.String(),
379
+		DriverStatus:       srv.runtime.driver.Status(),
379 380
 		MemoryLimit:        srv.runtime.capabilities.MemoryLimit,
380 381
 		SwapLimit:          srv.runtime.capabilities.SwapLimit,
381 382
 		IPv4Forwarding:     !srv.runtime.capabilities.IPv4ForwardingDisabled,