github.com/DaoCloud/dao@v0.0.0-20161212064103-c3dbfd13ee36/daemon/info.go (about) 1 package daemon 2 3 import ( 4 "os" 5 "runtime" 6 "sync/atomic" 7 "time" 8 9 "github.com/Sirupsen/logrus" 10 "github.com/docker/docker/container" 11 "github.com/docker/docker/dockerversion" 12 "github.com/docker/docker/pkg/fileutils" 13 "github.com/docker/docker/pkg/parsers/kernel" 14 "github.com/docker/docker/pkg/parsers/operatingsystem" 15 "github.com/docker/docker/pkg/platform" 16 "github.com/docker/docker/pkg/sysinfo" 17 "github.com/docker/docker/pkg/system" 18 "github.com/docker/docker/registry" 19 "github.com/docker/docker/utils" 20 "github.com/docker/docker/volume/drivers" 21 "github.com/docker/engine-api/types" 22 "github.com/docker/go-connections/sockets" 23 ) 24 25 // SystemInfo returns information about the host server the daemon is running on. 26 func (daemon *Daemon) SystemInfo() (*types.Info, error) { 27 kernelVersion := "<unknown>" 28 if kv, err := kernel.GetKernelVersion(); err != nil { 29 logrus.Warnf("Could not get kernel version: %v", err) 30 } else { 31 kernelVersion = kv.String() 32 } 33 34 operatingSystem := "<unknown>" 35 if s, err := operatingsystem.GetOperatingSystem(); err != nil { 36 logrus.Warnf("Could not get operating system name: %v", err) 37 } else { 38 operatingSystem = s 39 } 40 41 // Don't do containerized check on Windows 42 if runtime.GOOS != "windows" { 43 if inContainer, err := operatingsystem.IsContainerized(); err != nil { 44 logrus.Errorf("Could not determine if daemon is containerized: %v", err) 45 operatingSystem += " (error determining if containerized)" 46 } else if inContainer { 47 operatingSystem += " (containerized)" 48 } 49 } 50 51 meminfo, err := system.ReadMemInfo() 52 if err != nil { 53 logrus.Errorf("Could not read system memory info: %v", err) 54 meminfo = &system.MemInfo{} 55 } 56 57 sysInfo := sysinfo.New(true) 58 59 var cRunning, cPaused, cStopped int32 60 daemon.containers.ApplyAll(func(c *container.Container) { 61 switch c.StateString() { 62 case "paused": 63 atomic.AddInt32(&cPaused, 1) 64 case "running": 65 atomic.AddInt32(&cRunning, 1) 66 default: 67 atomic.AddInt32(&cStopped, 1) 68 } 69 }) 70 71 var securityOptions []string 72 if sysInfo.AppArmor { 73 securityOptions = append(securityOptions, "apparmor") 74 } 75 if sysInfo.Seccomp && supportsSeccomp { 76 securityOptions = append(securityOptions, "seccomp") 77 } 78 if selinuxEnabled() { 79 securityOptions = append(securityOptions, "selinux") 80 } 81 82 v := &types.Info{ 83 ID: daemon.ID, 84 Containers: int(cRunning + cPaused + cStopped), 85 ContainersRunning: int(cRunning), 86 ContainersPaused: int(cPaused), 87 ContainersStopped: int(cStopped), 88 Images: len(daemon.imageStore.Map()), 89 Driver: daemon.GraphDriverName(), 90 DriverStatus: daemon.layerStore.DriverStatus(), 91 Plugins: daemon.showPluginsInfo(), 92 IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled, 93 BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled, 94 BridgeNfIP6tables: !sysInfo.BridgeNFCallIP6TablesDisabled, 95 Debug: utils.IsDebugEnabled(), 96 NFd: fileutils.GetTotalUsedFds(), 97 NGoroutines: runtime.NumGoroutine(), 98 SystemTime: time.Now().Format(time.RFC3339Nano), 99 LoggingDriver: daemon.defaultLogConfig.Type, 100 CgroupDriver: daemon.getCgroupDriver(), 101 NEventsListener: daemon.EventsService.SubscribersCount(), 102 KernelVersion: kernelVersion, 103 OperatingSystem: operatingSystem, 104 IndexServerAddress: registry.IndexServer, 105 OSType: platform.OSType, 106 Architecture: platform.Architecture, 107 RegistryConfig: daemon.RegistryService.ServiceConfig(), 108 NCPU: runtime.NumCPU(), 109 MemTotal: meminfo.MemTotal, 110 DockerRootDir: daemon.configStore.Root, 111 Labels: daemon.configStore.Labels, 112 ExperimentalBuild: utils.ExperimentalBuild(), 113 ServerVersion: dockerversion.Version, 114 ClusterStore: daemon.configStore.ClusterStore, 115 ClusterAdvertise: daemon.configStore.ClusterAdvertise, 116 HTTPProxy: sockets.GetProxyEnv("http_proxy"), 117 HTTPSProxy: sockets.GetProxyEnv("https_proxy"), 118 NoProxy: sockets.GetProxyEnv("no_proxy"), 119 SecurityOptions: securityOptions, 120 } 121 122 // TODO Windows. Refactor this more once sysinfo is refactored into 123 // platform specific code. On Windows, sysinfo.cgroupMemInfo and 124 // sysinfo.cgroupCpuInfo will be nil otherwise and cause a SIGSEGV if 125 // an attempt is made to access through them. 126 if runtime.GOOS != "windows" { 127 v.MemoryLimit = sysInfo.MemoryLimit 128 v.SwapLimit = sysInfo.SwapLimit 129 v.KernelMemory = sysInfo.KernelMemory 130 v.OomKillDisable = sysInfo.OomKillDisable 131 v.CPUCfsPeriod = sysInfo.CPUCfsPeriod 132 v.CPUCfsQuota = sysInfo.CPUCfsQuota 133 v.CPUShares = sysInfo.CPUShares 134 v.CPUSet = sysInfo.Cpuset 135 v.Runtimes = daemon.configStore.GetAllRuntimes() 136 v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName() 137 } 138 139 hostname := "" 140 if hn, err := os.Hostname(); err != nil { 141 logrus.Warnf("Could not get hostname: %v", err) 142 } else { 143 hostname = hn 144 } 145 v.Name = hostname 146 147 return v, nil 148 } 149 150 // SystemVersion returns version information about the daemon. 151 func (daemon *Daemon) SystemVersion() types.Version { 152 v := types.Version{ 153 Version: dockerversion.Version, 154 GitCommit: dockerversion.GitCommit, 155 GoVersion: runtime.Version(), 156 Os: runtime.GOOS, 157 Arch: runtime.GOARCH, 158 BuildTime: dockerversion.BuildTime, 159 Experimental: utils.ExperimentalBuild(), 160 } 161 162 kernelVersion := "<unknown>" 163 if kv, err := kernel.GetKernelVersion(); err != nil { 164 logrus.Warnf("Could not get kernel version: %v", err) 165 } else { 166 kernelVersion = kv.String() 167 } 168 v.KernelVersion = kernelVersion 169 170 return v 171 } 172 173 func (daemon *Daemon) showPluginsInfo() types.PluginsInfo { 174 var pluginsInfo types.PluginsInfo 175 176 pluginsInfo.Volume = volumedrivers.GetDriverList() 177 178 networkDriverList := daemon.GetNetworkDriverList() 179 for nd := range networkDriverList { 180 pluginsInfo.Network = append(pluginsInfo.Network, nd) 181 } 182 183 pluginsInfo.Authorization = daemon.configStore.AuthorizationPlugins 184 185 return pluginsInfo 186 }