1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #772 from dotcloud/improve_version_info_cmds

* API: Improve version info cmds
This commit is contained in:
Guillaume J. Charmes 2013-06-03 06:36:09 -07:00
commit 0443cc351d
4 changed files with 53 additions and 43 deletions

View file

@ -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 {

View file

@ -392,15 +392,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
}
@ -421,14 +420,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
}

View file

@ -957,10 +957,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
@ -986,12 +988,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

View file

@ -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) {