From 61f8001c23dc4fbd7b1113f20b89a0dbade9aa82 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Fri, 24 Oct 2014 15:48:23 -0700 Subject: [PATCH] Expose # of CPUs and memory available on docker info. Signed-off-by: Andrea Luzzardi --- api/client/commands.go | 7 +++++++ daemon/info.go | 8 ++++++++ docs/man/docker-info.1.md | 2 ++ docs/sources/reference/api/docker_remote_api.md | 6 ++++++ docs/sources/reference/api/docker_remote_api_v1.16.md | 2 ++ docs/sources/reference/commandline/cli.md | 2 ++ 6 files changed, 27 insertions(+) diff --git a/api/client/commands.go b/api/client/commands.go index f4ced5ecff..2a7190d3d7 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -481,6 +481,13 @@ func (cli *DockerCli) CmdInfo(args ...string) error { fmt.Fprintf(cli.out, "Kernel Version: %s\n", remoteInfo.Get("KernelVersion")) fmt.Fprintf(cli.out, "Operating System: %s\n", remoteInfo.Get("OperatingSystem")) + if remoteInfo.Exists("NCPU") { + fmt.Fprintf(cli.out, "CPUs: %d\n", remoteInfo.GetInt("NCPU")) + } + if remoteInfo.Exists("MemTotal") { + fmt.Fprintf(cli.out, "Total Memory: %s\n", units.BytesSize(float64(remoteInfo.GetInt64("MemTotal")))) + } + if remoteInfo.GetBool("Debug") || os.Getenv("DEBUG") != "" { fmt.Fprintf(cli.out, "Debug mode (server): %v\n", remoteInfo.GetBool("Debug")) fmt.Fprintf(cli.out, "Debug mode (client): %v\n", os.Getenv("DEBUG") != "") diff --git a/daemon/info.go b/daemon/info.go index 3d3c9ba6ca..79af8cc21b 100644 --- a/daemon/info.go +++ b/daemon/info.go @@ -9,6 +9,7 @@ import ( "github.com/docker/docker/pkg/log" "github.com/docker/docker/pkg/parsers/kernel" "github.com/docker/docker/pkg/parsers/operatingsystem" + "github.com/docker/docker/pkg/system" "github.com/docker/docker/registry" "github.com/docker/docker/utils" ) @@ -37,6 +38,11 @@ func (daemon *Daemon) CmdInfo(job *engine.Job) engine.Status { operatingSystem += " (containerized)" } + meminfo, err := system.ReadMemInfo() + if err != nil { + log.Errorf("Could not read system memory info: %v", err) + } + // if we still have the original dockerinit binary from before we copied it locally, let's return the path to that, since that's more intuitive (the copied path is trivial to derive by hand given VERSION) initPath := utils.DockerInitPath("") if initPath == "" { @@ -67,6 +73,8 @@ func (daemon *Daemon) CmdInfo(job *engine.Job) engine.Status { v.Set("IndexServerAddress", registry.IndexServerAddress()) v.Set("InitSha1", dockerversion.INITSHA1) v.Set("InitPath", initPath) + v.SetInt("NCPU", runtime.NumCPU()) + v.SetInt64("MemTotal", meminfo.MemTotal) if _, err := v.WriteTo(job.Stdout); err != nil { return job.Error(err) } diff --git a/docs/man/docker-info.1.md b/docs/man/docker-info.1.md index bf64a7b543..0547b44b07 100644 --- a/docs/man/docker-info.1.md +++ b/docs/man/docker-info.1.md @@ -37,6 +37,8 @@ Here is a sample output: Execution Driver: native-0.2 Kernel Version: 3.13.0-24-generic Operating System: Ubuntu 14.04 LTS + CPUs: 1 + Total Memory: 2 GiB # HISTORY April 2014, Originally compiled by William Henry (whenry at redhat dot com) diff --git a/docs/sources/reference/api/docker_remote_api.md b/docs/sources/reference/api/docker_remote_api.md index 4dd7fff688..5d144b9075 100644 --- a/docs/sources/reference/api/docker_remote_api.md +++ b/docs/sources/reference/api/docker_remote_api.md @@ -44,6 +44,12 @@ You can still call an old version of the API using ### What's new +`GET /info` + +**New!** +`info` now returns the number of CPUs available on the machine (`NCPU`) and +total memory available (`MemTotal`). + ## v1.15 ### Full Documentation diff --git a/docs/sources/reference/api/docker_remote_api_v1.16.md b/docs/sources/reference/api/docker_remote_api_v1.16.md index 887bebcee1..fbb89294e2 100644 --- a/docs/sources/reference/api/docker_remote_api_v1.16.md +++ b/docs/sources/reference/api/docker_remote_api_v1.16.md @@ -1164,6 +1164,8 @@ Display system-wide information "Driver":"btrfs", "ExecutionDriver":"native-0.1", "KernelVersion":"3.12.0-1-amd64" + "NCPU":1, + "MemTotal":2099236864, "Debug":false, "NFd": 11, "NGoroutines":21, diff --git a/docs/sources/reference/commandline/cli.md b/docs/sources/reference/commandline/cli.md index 4ede5e9ccf..e1beaeb29c 100644 --- a/docs/sources/reference/commandline/cli.md +++ b/docs/sources/reference/commandline/cli.md @@ -812,6 +812,8 @@ For example: Execution Driver: native-0.2 Kernel Version: 3.13.0-24-generic Operating System: Ubuntu 14.04 LTS + CPUs: 1 + Total Memory: 2 GiB Debug mode (server): false Debug mode (client): true Fds: 10