github.com/brahmaroutu/docker@v1.2.1-0.20160809185609-eb28dde01f16/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: sysinfo.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 LiveRestoreEnabled: daemon.configStore.LiveRestoreEnabled, 121 } 122 123 // TODO Windows. Refactor this more once sysinfo is refactored into 124 // platform specific code. On Windows, sysinfo.cgroupMemInfo and 125 // sysinfo.cgroupCpuInfo will be nil otherwise and cause a SIGSEGV if 126 // an attempt is made to access through them. 127 if runtime.GOOS != "windows" { 128 v.MemoryLimit = sysInfo.MemoryLimit 129 v.SwapLimit = sysInfo.SwapLimit 130 v.KernelMemory = sysInfo.KernelMemory 131 v.OomKillDisable = sysInfo.OomKillDisable 132 v.CPUCfsPeriod = sysInfo.CPUCfsPeriod 133 v.CPUCfsQuota = sysInfo.CPUCfsQuota 134 v.CPUShares = sysInfo.CPUShares 135 v.CPUSet = sysInfo.Cpuset 136 v.Runtimes = daemon.configStore.GetAllRuntimes() 137 v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName() 138 } 139 140 hostname := "" 141 if hn, err := os.Hostname(); err != nil { 142 logrus.Warnf("Could not get hostname: %v", err) 143 } else { 144 hostname = hn 145 } 146 v.Name = hostname 147 148 return v, nil 149 } 150 151 // SystemVersion returns version information about the daemon. 152 func (daemon *Daemon) SystemVersion() types.Version { 153 v := types.Version{ 154 Version: dockerversion.Version, 155 GitCommit: dockerversion.GitCommit, 156 GoVersion: runtime.Version(), 157 Os: runtime.GOOS, 158 Arch: runtime.GOARCH, 159 BuildTime: dockerversion.BuildTime, 160 Experimental: utils.ExperimentalBuild(), 161 } 162 163 kernelVersion := "<unknown>" 164 if kv, err := kernel.GetKernelVersion(); err != nil { 165 logrus.Warnf("Could not get kernel version: %v", err) 166 } else { 167 kernelVersion = kv.String() 168 } 169 v.KernelVersion = kernelVersion 170 171 return v 172 } 173 174 func (daemon *Daemon) showPluginsInfo() types.PluginsInfo { 175 var pluginsInfo types.PluginsInfo 176 177 pluginsInfo.Volume = volumedrivers.GetDriverList() 178 179 networkDriverList := daemon.GetNetworkDriverList() 180 for nd := range networkDriverList { 181 pluginsInfo.Network = append(pluginsInfo.Network, nd) 182 } 183 184 pluginsInfo.Authorization = daemon.configStore.AuthorizationPlugins 185 186 return pluginsInfo 187 }