github.com/erriapo/docker@v1.6.0-rc2/daemon/info.go (about)

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