github.com/oyvindsk/docker@v1.5.0/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  	registryJob := job.Eng.Job("registry_config")
    59  	registryEnv, _ := registryJob.Stdout.AddEnv()
    60  	if err := registryJob.Run(); err != nil {
    61  		return job.Error(err)
    62  	}
    63  	registryConfig := registry.ServiceConfig{}
    64  	if err := registryEnv.GetJson("config", &registryConfig); err != nil {
    65  		return job.Error(err)
    66  	}
    67  	v := &engine.Env{}
    68  	v.SetJson("ID", daemon.ID)
    69  	v.SetInt("Containers", len(daemon.List()))
    70  	v.SetInt("Images", imgcount)
    71  	v.Set("Driver", daemon.GraphDriver().String())
    72  	v.SetJson("DriverStatus", daemon.GraphDriver().Status())
    73  	v.SetBool("MemoryLimit", daemon.SystemConfig().MemoryLimit)
    74  	v.SetBool("SwapLimit", daemon.SystemConfig().SwapLimit)
    75  	v.SetBool("IPv4Forwarding", !daemon.SystemConfig().IPv4ForwardingDisabled)
    76  	v.SetBool("Debug", os.Getenv("DEBUG") != "")
    77  	v.SetInt("NFd", utils.GetTotalUsedFds())
    78  	v.SetInt("NGoroutines", runtime.NumGoroutine())
    79  	v.Set("ExecutionDriver", daemon.ExecutionDriver().Name())
    80  	v.SetInt("NEventsListener", env.GetInt("count"))
    81  	v.Set("KernelVersion", kernelVersion)
    82  	v.Set("OperatingSystem", operatingSystem)
    83  	v.Set("IndexServerAddress", registry.IndexServerAddress())
    84  	v.SetJson("RegistryConfig", registryConfig)
    85  	v.Set("InitSha1", dockerversion.INITSHA1)
    86  	v.Set("InitPath", initPath)
    87  	v.SetInt("NCPU", runtime.NumCPU())
    88  	v.SetInt64("MemTotal", meminfo.MemTotal)
    89  	v.Set("DockerRootDir", daemon.Config().Root)
    90  	if hostname, err := os.Hostname(); err == nil {
    91  		v.SetJson("Name", hostname)
    92  	}
    93  	v.SetList("Labels", daemon.Config().Labels)
    94  	if _, err := v.WriteTo(job.Stdout); err != nil {
    95  		return job.Error(err)
    96  	}
    97  	return engine.StatusOK
    98  }