浏览代码

add LXC version to docker info in debug mode

Victor Vieux 12 年之前
父节点
当前提交
921c6994b1
共有 3 个文件被更改,包括 15 次插入4 次删除
  1. 5 4
      api_params.go
  2. 1 0
      commands.go
  3. 9 0
      server.go

+ 5 - 4
api_params.go

@@ -20,10 +20,11 @@ type APIInfo struct {
 	Debug       bool
 	Containers  int
 	Images      int
-	NFd         int  `json:",omitempty"`
-	NGoroutines int  `json:",omitempty"`
-	MemoryLimit bool `json:",omitempty"`
-	SwapLimit   bool `json:",omitempty"`
+	NFd         int    `json:",omitempty"`
+	NGoroutines int    `json:",omitempty"`
+	MemoryLimit bool   `json:",omitempty"`
+	SwapLimit   bool   `json:",omitempty"`
+	LXCVersion  string `json:",omitempty"`
 }
 
 type APITop struct {

+ 1 - 0
commands.go

@@ -463,6 +463,7 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
 		fmt.Fprintf(cli.out, "Debug mode (client): %v\n", os.Getenv("DEBUG") != "")
 		fmt.Fprintf(cli.out, "Fds: %d\n", out.NFd)
 		fmt.Fprintf(cli.out, "Goroutines: %d\n", out.NGoroutines)
+		fmt.Fprintf(cli.out, "LXC Version: %s\n", out.LXCVersion)
 	}
 	if !out.MemoryLimit {
 		fmt.Fprintf(cli.err, "WARNING: No memory limit support\n")

+ 9 - 0
server.go

@@ -208,6 +208,14 @@ func (srv *Server) DockerInfo() *APIInfo {
 	} else {
 		imgcount = len(images)
 	}
+	lxcVersion := ""
+	if output, err := exec.Command("lxc-version").CombinedOutput(); err == nil {
+		outputStr := string(output)
+		if len(strings.SplitN(outputStr, ":", 2)) == 2 {
+			lxcVersion = strings.TrimSpace(strings.SplitN(string(output), ":", 2)[1])
+		}
+	}
+
 	return &APIInfo{
 		Containers:  len(srv.runtime.List()),
 		Images:      imgcount,
@@ -216,6 +224,7 @@ func (srv *Server) DockerInfo() *APIInfo {
 		Debug:       os.Getenv("DEBUG") != "",
 		NFd:         utils.GetTotalUsedFds(),
 		NGoroutines: runtime.NumGoroutine(),
+		LXCVersion:  lxcVersion,
 	}
 }