Browse code

Expose # of CPUs and memory available on docker info.

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>

Andrea Luzzardi authored on 2014/10/25 07:48:23
Showing 6 changed files
... ...
@@ -481,6 +481,13 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
481 481
 	fmt.Fprintf(cli.out, "Kernel Version: %s\n", remoteInfo.Get("KernelVersion"))
482 482
 	fmt.Fprintf(cli.out, "Operating System: %s\n", remoteInfo.Get("OperatingSystem"))
483 483
 
484
+	if remoteInfo.Exists("NCPU") {
485
+		fmt.Fprintf(cli.out, "CPUs: %d\n", remoteInfo.GetInt("NCPU"))
486
+	}
487
+	if remoteInfo.Exists("MemTotal") {
488
+		fmt.Fprintf(cli.out, "Total Memory: %s\n", units.BytesSize(float64(remoteInfo.GetInt64("MemTotal"))))
489
+	}
490
+
484 491
 	if remoteInfo.GetBool("Debug") || os.Getenv("DEBUG") != "" {
485 492
 		fmt.Fprintf(cli.out, "Debug mode (server): %v\n", remoteInfo.GetBool("Debug"))
486 493
 		fmt.Fprintf(cli.out, "Debug mode (client): %v\n", os.Getenv("DEBUG") != "")
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"github.com/docker/docker/pkg/log"
10 10
 	"github.com/docker/docker/pkg/parsers/kernel"
11 11
 	"github.com/docker/docker/pkg/parsers/operatingsystem"
12
+	"github.com/docker/docker/pkg/system"
12 13
 	"github.com/docker/docker/registry"
13 14
 	"github.com/docker/docker/utils"
14 15
 )
... ...
@@ -37,6 +38,11 @@ func (daemon *Daemon) CmdInfo(job *engine.Job) engine.Status {
37 37
 		operatingSystem += " (containerized)"
38 38
 	}
39 39
 
40
+	meminfo, err := system.ReadMemInfo()
41
+	if err != nil {
42
+		log.Errorf("Could not read system memory info: %v", err)
43
+	}
44
+
40 45
 	// 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)
41 46
 	initPath := utils.DockerInitPath("")
42 47
 	if initPath == "" {
... ...
@@ -67,6 +73,8 @@ func (daemon *Daemon) CmdInfo(job *engine.Job) engine.Status {
67 67
 	v.Set("IndexServerAddress", registry.IndexServerAddress())
68 68
 	v.Set("InitSha1", dockerversion.INITSHA1)
69 69
 	v.Set("InitPath", initPath)
70
+	v.SetInt("NCPU", runtime.NumCPU())
71
+	v.SetInt64("MemTotal", meminfo.MemTotal)
70 72
 	if _, err := v.WriteTo(job.Stdout); err != nil {
71 73
 		return job.Error(err)
72 74
 	}
... ...
@@ -37,6 +37,8 @@ Here is a sample output:
37 37
     Execution Driver: native-0.2
38 38
     Kernel Version: 3.13.0-24-generic
39 39
     Operating System: Ubuntu 14.04 LTS
40
+    CPUs: 1
41
+    Total Memory: 2 GiB
40 42
 
41 43
 # HISTORY
42 44
 April 2014, Originally compiled by William Henry (whenry at redhat dot com)
... ...
@@ -44,6 +44,12 @@ You can still call an old version of the API using
44 44
 
45 45
 ### What's new
46 46
 
47
+`GET /info`
48
+
49
+**New!**
50
+`info` now returns the number of CPUs available on the machine (`NCPU`) and
51
+total memory available (`MemTotal`).
52
+
47 53
 ## v1.15
48 54
 
49 55
 ### Full Documentation
... ...
@@ -1164,6 +1164,8 @@ Display system-wide information
1164 1164
              "Driver":"btrfs",
1165 1165
              "ExecutionDriver":"native-0.1",
1166 1166
              "KernelVersion":"3.12.0-1-amd64"
1167
+             "NCPU":1,
1168
+             "MemTotal":2099236864,
1167 1169
              "Debug":false,
1168 1170
              "NFd": 11,
1169 1171
              "NGoroutines":21,
... ...
@@ -812,6 +812,8 @@ For example:
812 812
     Execution Driver: native-0.2
813 813
     Kernel Version: 3.13.0-24-generic
814 814
     Operating System: Ubuntu 14.04 LTS
815
+    CPUs: 1
816
+    Total Memory: 2 GiB
815 817
     Debug mode (server): false
816 818
     Debug mode (client): true
817 819
     Fds: 10