info.go 5.9 KB

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