github.com/gunjan5/docker@v1.8.2/daemon/info.go (about)

     1  package daemon
     2  
     3  import (
     4  	"os"
     5  	"runtime"
     6  	"time"
     7  
     8  	"github.com/Sirupsen/logrus"
     9  	"github.com/docker/docker/api/types"
    10  	"github.com/docker/docker/autogen/dockerversion"
    11  	"github.com/docker/docker/pkg/fileutils"
    12  	"github.com/docker/docker/pkg/parsers/kernel"
    13  	"github.com/docker/docker/pkg/parsers/operatingsystem"
    14  	"github.com/docker/docker/pkg/system"
    15  	"github.com/docker/docker/registry"
    16  	"github.com/docker/docker/utils"
    17  )
    18  
    19  func (daemon *Daemon) SystemInfo() (*types.Info, error) {
    20  	images := daemon.Graph().Map()
    21  	var imgcount int
    22  	if images == nil {
    23  		imgcount = 0
    24  	} else {
    25  		imgcount = len(images)
    26  	}
    27  	kernelVersion := "<unknown>"
    28  	if kv, err := kernel.GetKernelVersion(); err == nil {
    29  		kernelVersion = kv.String()
    30  	}
    31  
    32  	operatingSystem := "<unknown>"
    33  	if s, err := operatingsystem.GetOperatingSystem(); err == nil {
    34  		operatingSystem = s
    35  	}
    36  
    37  	// Don't do containerized check on Windows
    38  	if runtime.GOOS != "windows" {
    39  		if inContainer, err := operatingsystem.IsContainerized(); err != nil {
    40  			logrus.Errorf("Could not determine if daemon is containerized: %v", err)
    41  			operatingSystem += " (error determining if containerized)"
    42  		} else if inContainer {
    43  			operatingSystem += " (containerized)"
    44  		}
    45  	}
    46  
    47  	meminfo, err := system.ReadMemInfo()
    48  	if err != nil {
    49  		logrus.Errorf("Could not read system memory info: %v", err)
    50  	}
    51  
    52  	// 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)
    53  	initPath := utils.DockerInitPath("")
    54  	if initPath == "" {
    55  		// if that fails, we'll just return the path from the daemon
    56  		initPath = daemon.SystemInitPath()
    57  	}
    58  
    59  	v := &types.Info{
    60  		ID:                 daemon.ID,
    61  		Containers:         len(daemon.List()),
    62  		Images:             imgcount,
    63  		Driver:             daemon.GraphDriver().String(),
    64  		DriverStatus:       daemon.GraphDriver().Status(),
    65  		IPv4Forwarding:     !daemon.SystemConfig().IPv4ForwardingDisabled,
    66  		BridgeNfIptables:   !daemon.SystemConfig().BridgeNfCallIptablesDisabled,
    67  		BridgeNfIp6tables:  !daemon.SystemConfig().BridgeNfCallIp6tablesDisabled,
    68  		Debug:              os.Getenv("DEBUG") != "",
    69  		NFd:                fileutils.GetTotalUsedFds(),
    70  		NGoroutines:        runtime.NumGoroutine(),
    71  		SystemTime:         time.Now().Format(time.RFC3339Nano),
    72  		ExecutionDriver:    daemon.ExecutionDriver().Name(),
    73  		LoggingDriver:      daemon.defaultLogConfig.Type,
    74  		NEventsListener:    daemon.EventsService.SubscribersCount(),
    75  		KernelVersion:      kernelVersion,
    76  		OperatingSystem:    operatingSystem,
    77  		IndexServerAddress: registry.IndexServer,
    78  		RegistryConfig:     daemon.RegistryService.Config,
    79  		InitSha1:           dockerversion.INITSHA1,
    80  		InitPath:           initPath,
    81  		NCPU:               runtime.NumCPU(),
    82  		MemTotal:           meminfo.MemTotal,
    83  		DockerRootDir:      daemon.Config().Root,
    84  		Labels:             daemon.Config().Labels,
    85  		ExperimentalBuild:  utils.ExperimentalBuild(),
    86  	}
    87  
    88  	// TODO Windows. Refactor this more once sysinfo is refactored into
    89  	// platform specific code. On Windows, sysinfo.cgroupMemInfo and
    90  	// sysinfo.cgroupCpuInfo will be nil otherwise and cause a SIGSEGV if
    91  	// an attempt is made to access through them.
    92  	if runtime.GOOS != "windows" {
    93  		v.MemoryLimit = daemon.SystemConfig().MemoryLimit
    94  		v.SwapLimit = daemon.SystemConfig().SwapLimit
    95  		v.OomKillDisable = daemon.SystemConfig().OomKillDisable
    96  		v.CpuCfsPeriod = daemon.SystemConfig().CpuCfsPeriod
    97  		v.CpuCfsQuota = daemon.SystemConfig().CpuCfsQuota
    98  	}
    99  
   100  	if httpProxy := os.Getenv("http_proxy"); httpProxy != "" {
   101  		v.HttpProxy = httpProxy
   102  	}
   103  	if httpsProxy := os.Getenv("https_proxy"); httpsProxy != "" {
   104  		v.HttpsProxy = httpsProxy
   105  	}
   106  	if noProxy := os.Getenv("no_proxy"); noProxy != "" {
   107  		v.NoProxy = noProxy
   108  	}
   109  	if hostname, err := os.Hostname(); err == nil {
   110  		v.Name = hostname
   111  	}
   112  
   113  	return v, nil
   114  }