info.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package daemon
  2. import (
  3. "fmt"
  4. "os"
  5. "runtime"
  6. "sync/atomic"
  7. "time"
  8. "github.com/Sirupsen/logrus"
  9. "github.com/docker/docker/api"
  10. "github.com/docker/docker/api/types"
  11. "github.com/docker/docker/cli/debug"
  12. "github.com/docker/docker/container"
  13. "github.com/docker/docker/dockerversion"
  14. "github.com/docker/docker/pkg/fileutils"
  15. "github.com/docker/docker/pkg/parsers/kernel"
  16. "github.com/docker/docker/pkg/parsers/operatingsystem"
  17. "github.com/docker/docker/pkg/platform"
  18. "github.com/docker/docker/pkg/sysinfo"
  19. "github.com/docker/docker/pkg/system"
  20. "github.com/docker/docker/registry"
  21. "github.com/docker/docker/volume/drivers"
  22. "github.com/docker/go-connections/sockets"
  23. )
  24. // SystemInfo returns information about the host server the daemon is running on.
  25. func (daemon *Daemon) SystemInfo() (*types.Info, error) {
  26. kernelVersion := "<unknown>"
  27. if kv, err := kernel.GetKernelVersion(); err != nil {
  28. logrus.Warnf("Could not get kernel version: %v", err)
  29. } else {
  30. kernelVersion = kv.String()
  31. }
  32. operatingSystem := "<unknown>"
  33. if s, err := operatingsystem.GetOperatingSystem(); err != nil {
  34. logrus.Warnf("Could not get operating system name: %v", err)
  35. } else {
  36. operatingSystem = s
  37. }
  38. // Don't do containerized check on Windows
  39. if runtime.GOOS != "windows" {
  40. if inContainer, err := operatingsystem.IsContainerized(); err != nil {
  41. logrus.Errorf("Could not determine if daemon is containerized: %v", err)
  42. operatingSystem += " (error determining if containerized)"
  43. } else if inContainer {
  44. operatingSystem += " (containerized)"
  45. }
  46. }
  47. meminfo, err := system.ReadMemInfo()
  48. if err != nil {
  49. logrus.Errorf("Could not read system memory info: %v", err)
  50. meminfo = &system.MemInfo{}
  51. }
  52. sysInfo := sysinfo.New(true)
  53. var cRunning, cPaused, cStopped int32
  54. daemon.containers.ApplyAll(func(c *container.Container) {
  55. switch c.StateString() {
  56. case "paused":
  57. atomic.AddInt32(&cPaused, 1)
  58. case "running":
  59. atomic.AddInt32(&cRunning, 1)
  60. default:
  61. atomic.AddInt32(&cStopped, 1)
  62. }
  63. })
  64. securityOptions := []string{}
  65. if sysInfo.AppArmor {
  66. securityOptions = append(securityOptions, "name=apparmor")
  67. }
  68. if sysInfo.Seccomp && supportsSeccomp {
  69. profile := daemon.seccompProfilePath
  70. if profile == "" {
  71. profile = "default"
  72. }
  73. securityOptions = append(securityOptions, fmt.Sprintf("name=seccomp,profile=%s", profile))
  74. }
  75. if selinuxEnabled() {
  76. securityOptions = append(securityOptions, "name=selinux")
  77. }
  78. uid, gid := daemon.GetRemappedUIDGID()
  79. if uid != 0 || gid != 0 {
  80. securityOptions = append(securityOptions, "name=userns")
  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: debug.IsEnabled(),
  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: daemon.configStore.Experimental,
  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. LiveRestoreEnabled: daemon.configStore.LiveRestoreEnabled,
  120. SecurityOptions: securityOptions,
  121. Isolation: daemon.defaultIsolation,
  122. }
  123. // Retrieve platform specific info
  124. daemon.FillPlatformInfo(v, sysInfo)
  125. hostname := ""
  126. if hn, err := os.Hostname(); err != nil {
  127. logrus.Warnf("Could not get hostname: %v", err)
  128. } else {
  129. hostname = hn
  130. }
  131. v.Name = hostname
  132. return v, nil
  133. }
  134. // SystemVersion returns version information about the daemon.
  135. func (daemon *Daemon) SystemVersion() types.Version {
  136. v := types.Version{
  137. Version: dockerversion.Version,
  138. GitCommit: dockerversion.GitCommit,
  139. MinAPIVersion: api.MinVersion,
  140. GoVersion: runtime.Version(),
  141. Os: runtime.GOOS,
  142. Arch: runtime.GOARCH,
  143. BuildTime: dockerversion.BuildTime,
  144. Experimental: daemon.configStore.Experimental,
  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. pluginsInfo.Network = daemon.GetNetworkDriverList()
  159. pluginsInfo.Authorization = daemon.configStore.GetAuthorizationPlugins()
  160. return pluginsInfo
  161. }