Skip to content
Snippets Groups Projects
Commit 1dae7a25 authored by Guillaume J. Charmes's avatar Guillaume J. Charmes
Browse files

Improve the docker version and docker info commands

parent 926c1d45
No related branches found
No related tags found
No related merge requests found
......@@ -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 {
Debug bool
Containers int
Version string
Images int
Debug bool
GoVersion string
NFd int `json:",omitempty"`
NGoroutines int `json:",omitempty"`
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 {
......
......@@ -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
}
......
......@@ -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 out
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(),
}
}
func (srv *Server) ImageHistory(name string) ([]ApiHistory, error) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment