github.com/darciopacifico/docker@v1.9.0-rc1/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/sysinfo" 15 "github.com/docker/docker/pkg/system" 16 "github.com/docker/docker/registry" 17 "github.com/docker/docker/utils" 18 ) 19 20 // SystemInfo returns information about the host server the daemon is running on. 21 func (daemon *Daemon) SystemInfo() (*types.Info, error) { 22 images := daemon.Graph().Map() 23 var imgcount int 24 if images == nil { 25 imgcount = 0 26 } else { 27 imgcount = len(images) 28 } 29 kernelVersion := "<unknown>" 30 if kv, err := kernel.GetKernelVersion(); err == nil { 31 kernelVersion = kv.String() 32 } 33 34 operatingSystem := "<unknown>" 35 if s, err := operatingsystem.GetOperatingSystem(); err == nil { 36 operatingSystem = s 37 } 38 39 // Don't do containerized check on Windows 40 if runtime.GOOS != "windows" { 41 if inContainer, err := operatingsystem.IsContainerized(); err != nil { 42 logrus.Errorf("Could not determine if daemon is containerized: %v", err) 43 operatingSystem += " (error determining if containerized)" 44 } else if inContainer { 45 operatingSystem += " (containerized)" 46 } 47 } 48 49 meminfo, err := system.ReadMemInfo() 50 if err != nil { 51 logrus.Errorf("Could not read system memory info: %v", err) 52 } 53 54 // if we still have the original dockerinit binary from before 55 // we copied it locally, let's return the path to that, since 56 // that's more intuitive (the copied path is trivial to derive 57 // by hand given VERSION) 58 initPath := utils.DockerInitPath("") 59 if initPath == "" { 60 // if that fails, we'll just return the path from the daemon 61 initPath = daemon.systemInitPath() 62 } 63 64 sysInfo := sysinfo.New(true) 65 66 v := &types.Info{ 67 ID: daemon.ID, 68 Containers: len(daemon.List()), 69 Images: imgcount, 70 Driver: daemon.GraphDriver().String(), 71 DriverStatus: daemon.GraphDriver().Status(), 72 IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled, 73 BridgeNfIptables: !sysInfo.BridgeNfCallIptablesDisabled, 74 BridgeNfIP6tables: !sysInfo.BridgeNfCallIP6tablesDisabled, 75 Debug: os.Getenv("DEBUG") != "", 76 NFd: fileutils.GetTotalUsedFds(), 77 NGoroutines: runtime.NumGoroutine(), 78 SystemTime: time.Now().Format(time.RFC3339Nano), 79 ExecutionDriver: daemon.ExecutionDriver().Name(), 80 LoggingDriver: daemon.defaultLogConfig.Type, 81 NEventsListener: daemon.EventsService.SubscribersCount(), 82 KernelVersion: kernelVersion, 83 OperatingSystem: operatingSystem, 84 IndexServerAddress: registry.IndexServer, 85 RegistryConfig: daemon.RegistryService.Config, 86 InitSha1: dockerversion.INITSHA1, 87 InitPath: initPath, 88 NCPU: runtime.NumCPU(), 89 MemTotal: meminfo.MemTotal, 90 DockerRootDir: daemon.config().Root, 91 Labels: daemon.config().Labels, 92 ExperimentalBuild: utils.ExperimentalBuild(), 93 ServerVersion: dockerversion.VERSION, 94 ClusterStore: daemon.config().ClusterStore, 95 } 96 97 // TODO Windows. Refactor this more once sysinfo is refactored into 98 // platform specific code. On Windows, sysinfo.cgroupMemInfo and 99 // sysinfo.cgroupCpuInfo will be nil otherwise and cause a SIGSEGV if 100 // an attempt is made to access through them. 101 if runtime.GOOS != "windows" { 102 v.MemoryLimit = sysInfo.MemoryLimit 103 v.SwapLimit = sysInfo.SwapLimit 104 v.OomKillDisable = sysInfo.OomKillDisable 105 v.CPUCfsPeriod = sysInfo.CPUCfsPeriod 106 v.CPUCfsQuota = sysInfo.CPUCfsQuota 107 } 108 109 if httpProxy := os.Getenv("http_proxy"); httpProxy != "" { 110 v.HTTPProxy = httpProxy 111 } 112 if httpsProxy := os.Getenv("https_proxy"); httpsProxy != "" { 113 v.HTTPSProxy = httpsProxy 114 } 115 if noProxy := os.Getenv("no_proxy"); noProxy != "" { 116 v.NoProxy = noProxy 117 } 118 if hostname, err := os.Hostname(); err == nil { 119 v.Name = hostname 120 } 121 122 return v, nil 123 }