github.com/vincentwoo/docker@v0.7.3-0.20160116130405-82401a4b13c0/daemon/info.go (about) 1 package daemon 2 3 import ( 4 "os" 5 "runtime" 6 "strings" 7 "time" 8 9 "github.com/Sirupsen/logrus" 10 "github.com/docker/docker/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/platform" 15 "github.com/docker/docker/pkg/sysinfo" 16 "github.com/docker/docker/pkg/system" 17 "github.com/docker/docker/registry" 18 "github.com/docker/docker/utils" 19 "github.com/docker/docker/volume/drivers" 20 "github.com/docker/engine-api/types" 21 ) 22 23 // SystemInfo returns information about the host server the daemon is running on. 24 func (daemon *Daemon) SystemInfo() (*types.Info, error) { 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 35 // Don't do containerized check on Windows 36 if runtime.GOOS != "windows" { 37 if inContainer, err := operatingsystem.IsContainerized(); err != nil { 38 logrus.Errorf("Could not determine if daemon is containerized: %v", err) 39 operatingSystem += " (error determining if containerized)" 40 } else if inContainer { 41 operatingSystem += " (containerized)" 42 } 43 } 44 45 meminfo, err := system.ReadMemInfo() 46 if err != nil { 47 logrus.Errorf("Could not read system memory info: %v", err) 48 } 49 50 // if we still have the original dockerinit binary from before 51 // we copied it locally, let's return the path to that, since 52 // that's more intuitive (the copied path is trivial to derive 53 // by hand given VERSION) 54 initPath := utils.DockerInitPath("") 55 sysInfo := sysinfo.New(true) 56 57 var cRunning, cPaused, cStopped int 58 for _, c := range daemon.List() { 59 switch c.StateString() { 60 case "paused": 61 cPaused++ 62 case "running": 63 cRunning++ 64 default: 65 cStopped++ 66 } 67 } 68 69 v := &types.Info{ 70 ID: daemon.ID, 71 Containers: len(daemon.List()), 72 ContainersRunning: cRunning, 73 ContainersPaused: cPaused, 74 ContainersStopped: cStopped, 75 Images: len(daemon.imageStore.Map()), 76 Driver: daemon.GraphDriverName(), 77 DriverStatus: daemon.layerStore.DriverStatus(), 78 Plugins: daemon.showPluginsInfo(), 79 IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled, 80 BridgeNfIptables: !sysInfo.BridgeNfCallIptablesDisabled, 81 BridgeNfIP6tables: !sysInfo.BridgeNfCallIP6tablesDisabled, 82 Debug: utils.IsDebugEnabled(), 83 NFd: fileutils.GetTotalUsedFds(), 84 NGoroutines: runtime.NumGoroutine(), 85 SystemTime: time.Now().Format(time.RFC3339Nano), 86 ExecutionDriver: daemon.ExecutionDriver().Name(), 87 LoggingDriver: daemon.defaultLogConfig.Type, 88 NEventsListener: daemon.EventsService.SubscribersCount(), 89 KernelVersion: kernelVersion, 90 OperatingSystem: operatingSystem, 91 IndexServerAddress: registry.IndexServer, 92 OSType: platform.OSType, 93 Architecture: platform.Architecture, 94 RegistryConfig: daemon.RegistryService.Config, 95 InitSha1: dockerversion.InitSHA1, 96 InitPath: initPath, 97 NCPU: runtime.NumCPU(), 98 MemTotal: meminfo.MemTotal, 99 DockerRootDir: daemon.configStore.Root, 100 Labels: daemon.configStore.Labels, 101 ExperimentalBuild: utils.ExperimentalBuild(), 102 ServerVersion: dockerversion.Version, 103 ClusterStore: daemon.configStore.ClusterStore, 104 ClusterAdvertise: daemon.configStore.ClusterAdvertise, 105 HTTPProxy: getProxyEnv("http_proxy"), 106 HTTPSProxy: getProxyEnv("https_proxy"), 107 NoProxy: getProxyEnv("no_proxy"), 108 } 109 110 // TODO Windows. Refactor this more once sysinfo is refactored into 111 // platform specific code. On Windows, sysinfo.cgroupMemInfo and 112 // sysinfo.cgroupCpuInfo will be nil otherwise and cause a SIGSEGV if 113 // an attempt is made to access through them. 114 if runtime.GOOS != "windows" { 115 v.MemoryLimit = sysInfo.MemoryLimit 116 v.SwapLimit = sysInfo.SwapLimit 117 v.OomKillDisable = sysInfo.OomKillDisable 118 v.CPUCfsPeriod = sysInfo.CPUCfsPeriod 119 v.CPUCfsQuota = sysInfo.CPUCfsQuota 120 v.CPUShares = sysInfo.CPUShares 121 v.CPUSet = sysInfo.Cpuset 122 } 123 124 if hostname, err := os.Hostname(); err == nil { 125 v.Name = hostname 126 } 127 128 return v, nil 129 } 130 131 // SystemVersion returns version information about the daemon. 132 func (daemon *Daemon) SystemVersion() types.Version { 133 v := types.Version{ 134 Version: dockerversion.Version, 135 GitCommit: dockerversion.GitCommit, 136 GoVersion: runtime.Version(), 137 Os: runtime.GOOS, 138 Arch: runtime.GOARCH, 139 BuildTime: dockerversion.BuildTime, 140 Experimental: utils.ExperimentalBuild(), 141 } 142 143 if kernelVersion, err := kernel.GetKernelVersion(); err == nil { 144 v.KernelVersion = kernelVersion.String() 145 } 146 147 return v 148 } 149 150 func (daemon *Daemon) showPluginsInfo() types.PluginsInfo { 151 var pluginsInfo types.PluginsInfo 152 153 pluginsInfo.Volume = volumedrivers.GetDriverList() 154 155 networkDriverList := daemon.GetNetworkDriverList() 156 for nd := range networkDriverList { 157 pluginsInfo.Network = append(pluginsInfo.Network, nd) 158 } 159 160 pluginsInfo.Authorization = daemon.configStore.AuthorizationPlugins 161 162 return pluginsInfo 163 } 164 165 // The uppercase and the lowercase are available for the proxy settings. 166 // See the Go specification for details on these variables. https://golang.org/pkg/net/http/ 167 func getProxyEnv(key string) string { 168 proxyValue := os.Getenv(strings.ToUpper(key)) 169 if proxyValue == "" { 170 return os.Getenv(strings.ToLower(key)) 171 } 172 return proxyValue 173 }