info.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. }
  49. sysInfo := sysinfo.New(true)
  50. var cRunning, cPaused, cStopped int32
  51. daemon.containers.ApplyAll(func(c *container.Container) {
  52. switch c.StateString() {
  53. case "paused":
  54. atomic.AddInt32(&cPaused, 1)
  55. case "running":
  56. atomic.AddInt32(&cRunning, 1)
  57. default:
  58. atomic.AddInt32(&cStopped, 1)
  59. }
  60. })
  61. var securityOptions []string
  62. if sysInfo.AppArmor {
  63. securityOptions = append(securityOptions, "apparmor")
  64. }
  65. if sysInfo.Seccomp && supportsSeccomp {
  66. securityOptions = append(securityOptions, "seccomp")
  67. }
  68. if selinuxEnabled() {
  69. securityOptions = append(securityOptions, "selinux")
  70. }
  71. v := &types.Info{
  72. ID: daemon.ID,
  73. Containers: int(cRunning + cPaused + cStopped),
  74. ContainersRunning: int(cRunning),
  75. ContainersPaused: int(cPaused),
  76. ContainersStopped: int(cStopped),
  77. Images: len(daemon.imageStore.Map()),
  78. Driver: daemon.GraphDriverName(),
  79. DriverStatus: daemon.layerStore.DriverStatus(),
  80. Plugins: daemon.showPluginsInfo(),
  81. IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled,
  82. BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled,
  83. BridgeNfIP6tables: !sysInfo.BridgeNFCallIP6TablesDisabled,
  84. Debug: utils.IsDebugEnabled(),
  85. NFd: fileutils.GetTotalUsedFds(),
  86. NGoroutines: runtime.NumGoroutine(),
  87. SystemTime: time.Now().Format(time.RFC3339Nano),
  88. LoggingDriver: daemon.defaultLogConfig.Type,
  89. CgroupDriver: daemon.getCgroupDriver(),
  90. NEventsListener: daemon.EventsService.SubscribersCount(),
  91. KernelVersion: kernelVersion,
  92. OperatingSystem: operatingSystem,
  93. IndexServerAddress: registry.IndexServer,
  94. OSType: platform.OSType,
  95. Architecture: platform.Architecture,
  96. RegistryConfig: daemon.RegistryService.ServiceConfig(),
  97. NCPU: sysinfo.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: sockets.GetProxyEnv("http_proxy"),
  106. HTTPSProxy: sockets.GetProxyEnv("https_proxy"),
  107. NoProxy: sockets.GetProxyEnv("no_proxy"),
  108. SecurityOptions: securityOptions,
  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.KernelMemory = sysInfo.KernelMemory
  118. v.OomKillDisable = sysInfo.OomKillDisable
  119. v.CPUCfsPeriod = sysInfo.CPUCfsPeriod
  120. v.CPUCfsQuota = sysInfo.CPUCfsQuota
  121. v.CPUShares = sysInfo.CPUShares
  122. v.CPUSet = sysInfo.Cpuset
  123. v.Runtimes = daemon.configStore.GetAllRuntimes()
  124. v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName()
  125. }
  126. hostname := ""
  127. if hn, err := os.Hostname(); err != nil {
  128. logrus.Warnf("Could not get hostname: %v", err)
  129. } else {
  130. hostname = hn
  131. }
  132. v.Name = hostname
  133. return v, nil
  134. }
  135. // SystemVersion returns version information about the daemon.
  136. func (daemon *Daemon) SystemVersion() types.Version {
  137. v := types.Version{
  138. Version: dockerversion.Version,
  139. GitCommit: dockerversion.GitCommit,
  140. GoVersion: runtime.Version(),
  141. Os: runtime.GOOS,
  142. Arch: runtime.GOARCH,
  143. BuildTime: dockerversion.BuildTime,
  144. Experimental: utils.ExperimentalBuild(),
  145. }
  146. kernelVersion := "<unknown>"
  147. if kv, err := kernel.GetKernelVersion(); err != nil {
  148. logrus.Warnf("Could not get kernel version: %v", err)
  149. } else {
  150. kernelVersion = kv.String()
  151. }
  152. v.KernelVersion = kernelVersion
  153. return v
  154. }
  155. func (daemon *Daemon) showPluginsInfo() types.PluginsInfo {
  156. var pluginsInfo types.PluginsInfo
  157. pluginsInfo.Volume = volumedrivers.GetDriverList()
  158. networkDriverList := daemon.GetNetworkDriverList()
  159. for nd := range networkDriverList {
  160. pluginsInfo.Network = append(pluginsInfo.Network, nd)
  161. }
  162. pluginsInfo.Authorization = daemon.configStore.AuthorizationPlugins
  163. return pluginsInfo
  164. }