github.com/fcwu/docker@v1.4.2-0.20150115145920-2a69ca89f0df/daemon/info.go (about)

     1  package daemon
     2  
     3  import (
     4  	"os"
     5  	"runtime"
     6  
     7  	log "github.com/Sirupsen/logrus"
     8  	"github.com/docker/docker/dockerversion"
     9  	"github.com/docker/docker/engine"
    10  	"github.com/docker/docker/pkg/parsers/kernel"
    11  	"github.com/docker/docker/pkg/parsers/operatingsystem"
    12  	"github.com/docker/docker/pkg/system"
    13  	"github.com/docker/docker/registry"
    14  	"github.com/docker/docker/utils"
    15  )
    16  
    17  func (daemon *Daemon) CmdInfo(job *engine.Job) engine.Status {
    18  	images, _ := daemon.Graph().Map()
    19  	var imgcount int
    20  	if images == nil {
    21  		imgcount = 0
    22  	} else {
    23  		imgcount = len(images)
    24  	}
    25  	kernelVersion := "<unknown>"
    26  	if kv, err := kernel.GetKernelVersion(); err == nil {
    27  		kernelVersion = kv.String()
    28  	}
    29  
    30  	operatingSystem := "<unknown>"
    31  	if s, err := operatingsystem.GetOperatingSystem(); err == nil {
    32  		operatingSystem = s
    33  	}
    34  	if inContainer, err := operatingsystem.IsContainerized(); err != nil {
    35  		log.Errorf("Could not determine if daemon is containerized: %v", err)
    36  		operatingSystem += " (error determining if containerized)"
    37  	} else if inContainer {
    38  		operatingSystem += " (containerized)"
    39  	}
    40  
    41  	meminfo, err := system.ReadMemInfo()
    42  	if err != nil {
    43  		log.Errorf("Could not read system memory info: %v", err)
    44  	}
    45  
    46  	// 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)
    47  	initPath := utils.DockerInitPath("")
    48  	if initPath == "" {
    49  		// if that fails, we'll just return the path from the daemon
    50  		initPath = daemon.SystemInitPath()
    51  	}
    52  
    53  	cjob := job.Eng.Job("subscribers_count")
    54  	env, _ := cjob.Stdout.AddEnv()
    55  	if err := cjob.Run(); err != nil {
    56  		return job.Error(err)
    57  	}
    58  	v := &engine.Env{}
    59  	v.SetJson("ID", daemon.ID)
    60  	v.SetInt("Containers", len(daemon.List()))
    61  	v.SetInt("Images", imgcount)
    62  	v.Set("Driver", daemon.GraphDriver().String())
    63  	v.SetJson("DriverStatus", daemon.GraphDriver().Status())
    64  	v.SetBool("MemoryLimit", daemon.SystemConfig().MemoryLimit)
    65  	v.SetBool("SwapLimit", daemon.SystemConfig().SwapLimit)
    66  	v.SetBool("IPv4Forwarding", !daemon.SystemConfig().IPv4ForwardingDisabled)
    67  	v.SetBool("Debug", os.Getenv("DEBUG") != "")
    68  	v.SetInt("NFd", utils.GetTotalUsedFds())
    69  	v.SetInt("NGoroutines", runtime.NumGoroutine())
    70  	v.Set("ExecutionDriver", daemon.ExecutionDriver().Name())
    71  	v.SetInt("NEventsListener", env.GetInt("count"))
    72  	v.Set("KernelVersion", kernelVersion)
    73  	v.Set("OperatingSystem", operatingSystem)
    74  	v.Set("IndexServerAddress", registry.IndexServerAddress())
    75  	v.Set("InitSha1", dockerversion.INITSHA1)
    76  	v.Set("InitPath", initPath)
    77  	v.SetInt("NCPU", runtime.NumCPU())
    78  	v.SetInt64("MemTotal", meminfo.MemTotal)
    79  	v.Set("DockerRootDir", daemon.Config().Root)
    80  	if hostname, err := os.Hostname(); err == nil {
    81  		v.SetJson("Name", hostname)
    82  	}
    83  	v.SetList("Labels", daemon.Config().Labels)
    84  	if _, err := v.WriteTo(job.Stdout); err != nil {
    85  		return job.Error(err)
    86  	}
    87  	return engine.StatusOK
    88  }