From 1dae7a25b919dc70798cbab8107809690212cd69 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 31 May 2013 15:53:57 -0700 Subject: [PATCH 1/2] Improve the docker version and docker info commands --- api_params.go | 23 +++++++++++------------ commands.go | 34 +++++++++++++++++++++------------- server.go | 26 ++++++++++++++------------ 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/api_params.go b/api_params.go index 1a24ab2875..e18238b735 100644 --- a/api_params.go +++ b/api_params.go @@ -3,7 +3,7 @@ package docker type ApiHistory struct { Id string Created int64 - CreatedBy string + CreatedBy string `json:",omitempty"` } type ApiImages struct { @@ -14,13 +14,13 @@ type ApiImages struct { } type ApiInfo struct { - Containers int - Version string - Images int Debug bool - GoVersion string - NFd int `json:",omitempty"` - NGoroutines int `json:",omitempty"` + Containers int + Images int + NFd int `json:",omitempty"` + NGoroutines int `json:",omitempty"` + MemoryLimit bool `json:",omitempty"` + SwapLimit bool `json:",omitempty"` } type ApiContainers struct { @@ -43,7 +43,7 @@ type ApiId struct { type ApiRun struct { Id string - Warnings []string + Warnings []string `json:",omitempty"` } type ApiPort struct { @@ -51,10 +51,9 @@ type ApiPort struct { } type ApiVersion struct { - Version string - GitCommit string - MemoryLimit bool - SwapLimit bool + Version string + GitCommit string `json:",omitempty"` + GoVersion string `json:",omitempty"` } type ApiWait struct { diff --git a/commands.go b/commands.go index 6109aebb13..9765b85cab 100644 --- a/commands.go +++ b/commands.go @@ -391,15 +391,14 @@ func (cli *DockerCli) CmdVersion(args ...string) error { utils.Debugf("Error unmarshal: body: %s, err: %s\n", body, err) return err } - fmt.Println("Version:", out.Version) - fmt.Println("Git Commit:", out.GitCommit) - if !out.MemoryLimit { - fmt.Println("WARNING: No memory limit support") + fmt.Println("Client version:", VERSION) + fmt.Println("Server version:", out.Version) + if out.GitCommit != "" { + fmt.Println("Git commit:", out.GitCommit) } - if !out.SwapLimit { - fmt.Println("WARNING: No swap limit support") + if out.GoVersion != "" { + fmt.Println("Go version:", out.GoVersion) } - return nil } @@ -420,14 +419,23 @@ func (cli *DockerCli) CmdInfo(args ...string) error { } var out ApiInfo - err = json.Unmarshal(body, &out) - if err != nil { + if err := json.Unmarshal(body, &out); err != nil { return err } - fmt.Printf("containers: %d\nversion: %s\nimages: %d\nGo version: %s\n", out.Containers, out.Version, out.Images, out.GoVersion) - if out.Debug { - fmt.Println("debug mode enabled") - fmt.Printf("fds: %d\ngoroutines: %d\n", out.NFd, out.NGoroutines) + + fmt.Printf("Containers: %d\n", out.Containers) + fmt.Printf("Images: %d\n", out.Images) + if out.Debug || os.Getenv("DEBUG") != "" { + fmt.Printf("Debug mode (server): %v\n", out.Debug) + fmt.Printf("Debug mode (client): %v\n", os.Getenv("DEBUG") != "") + fmt.Printf("Fds: %d\n", out.NFd) + fmt.Printf("Goroutines: %d\n", out.NGoroutines) + } + if !out.MemoryLimit { + fmt.Println("WARNING: No memory limit support") + } + if !out.SwapLimit { + fmt.Println("WARNING: No swap limit support") } return nil } diff --git a/server.go b/server.go index 90ec79986c..088353c3f7 100644 --- a/server.go +++ b/server.go @@ -17,7 +17,11 @@ import ( ) func (srv *Server) DockerVersion() ApiVersion { - return ApiVersion{VERSION, GIT_COMMIT, srv.runtime.capabilities.MemoryLimit, srv.runtime.capabilities.SwapLimit} + return ApiVersion{ + Version: VERSION, + GitCommit: GIT_COMMIT, + GoVersion: runtime.Version(), + } } func (srv *Server) ContainerKill(name string) error { @@ -187,7 +191,7 @@ func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) { return outs, nil } -func (srv *Server) DockerInfo() ApiInfo { +func (srv *Server) DockerInfo() *ApiInfo { images, _ := srv.runtime.graph.All() var imgcount int if images == nil { @@ -195,17 +199,15 @@ func (srv *Server) DockerInfo() ApiInfo { } else { imgcount = len(images) } - var out ApiInfo - out.Containers = len(srv.runtime.List()) - out.Version = VERSION - out.Images = imgcount - out.GoVersion = runtime.Version() - if os.Getenv("DEBUG") != "" { - out.Debug = true - out.NFd = utils.GetTotalUsedFds() - out.NGoroutines = runtime.NumGoroutine() + return &ApiInfo{ + Containers: len(srv.runtime.List()), + Images: imgcount, + MemoryLimit: srv.runtime.capabilities.MemoryLimit, + SwapLimit: srv.runtime.capabilities.SwapLimit, + Debug: os.Getenv("DEBUG") != "", + NFd: utils.GetTotalUsedFds(), + NGoroutines: runtime.NumGoroutine(), } - return out } func (srv *Server) ImageHistory(name string) ([]ApiHistory, error) { From f41d2ec4d91f2fa1dc479d8bac32113fbb7e987e Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 31 May 2013 15:56:30 -0700 Subject: [PATCH 2/2] Update api docs --- docs/sources/api/docker_remote_api.rst | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/sources/api/docker_remote_api.rst b/docs/sources/api/docker_remote_api.rst index 5056a62a19..e350b9746c 100644 --- a/docs/sources/api/docker_remote_api.rst +++ b/docs/sources/api/docker_remote_api.rst @@ -914,10 +914,12 @@ Display system-wide information { "Containers":11, - "Version":"0.2.2", "Images":16, - "GoVersion":"go1.0.3", - "Debug":false + "Debug":false, + "NFd": 11, + "NGoroutines":21, + "MemoryLimit":true, + "SwapLimit":false } :statuscode 200: no error @@ -943,12 +945,11 @@ Show the docker version information HTTP/1.1 200 OK Content-Type: application/json - + { "Version":"0.2.2", "GitCommit":"5a2a5cc+CHANGES", - "MemoryLimit":true, - "SwapLimit":false + "GoVersion":"go1.0.3" } :statuscode 200: no error