info.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. package daemon
  2. import (
  3. "fmt"
  4. "os"
  5. "runtime"
  6. "strings"
  7. "time"
  8. "github.com/docker/docker/api"
  9. "github.com/docker/docker/api/types"
  10. "github.com/docker/docker/cli/debug"
  11. "github.com/docker/docker/daemon/logger"
  12. "github.com/docker/docker/dockerversion"
  13. "github.com/docker/docker/pkg/fileutils"
  14. "github.com/docker/docker/pkg/parsers/kernel"
  15. "github.com/docker/docker/pkg/parsers/operatingsystem"
  16. "github.com/docker/docker/pkg/platform"
  17. "github.com/docker/docker/pkg/sysinfo"
  18. "github.com/docker/docker/pkg/system"
  19. "github.com/docker/docker/registry"
  20. "github.com/docker/docker/volume/drivers"
  21. "github.com/docker/go-connections/sockets"
  22. "github.com/sirupsen/logrus"
  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. cRunning, cPaused, cStopped := stateCtr.get()
  54. securityOptions := []string{}
  55. if sysInfo.AppArmor {
  56. securityOptions = append(securityOptions, "name=apparmor")
  57. }
  58. if sysInfo.Seccomp && supportsSeccomp {
  59. profile := daemon.seccompProfilePath
  60. if profile == "" {
  61. profile = "default"
  62. }
  63. securityOptions = append(securityOptions, fmt.Sprintf("name=seccomp,profile=%s", profile))
  64. }
  65. if selinuxEnabled() {
  66. securityOptions = append(securityOptions, "name=selinux")
  67. }
  68. rootIDs := daemon.idMappings.RootPair()
  69. if rootIDs.UID != 0 || rootIDs.GID != 0 {
  70. securityOptions = append(securityOptions, "name=userns")
  71. }
  72. imageCount := 0
  73. drivers := ""
  74. for p, ds := range daemon.stores {
  75. imageCount += len(ds.imageStore.Map())
  76. drivers += daemon.GraphDriverName(p)
  77. if len(daemon.stores) > 1 {
  78. drivers += fmt.Sprintf(" (%s) ", p)
  79. }
  80. }
  81. // TODO @jhowardmsft LCOW support. For now, hard-code the platform shown for the driver status
  82. p := runtime.GOOS
  83. if system.LCOWSupported() {
  84. p = "linux"
  85. }
  86. drivers = strings.TrimSpace(drivers)
  87. v := &types.Info{
  88. ID: daemon.ID,
  89. Containers: cRunning + cPaused + cStopped,
  90. ContainersRunning: cRunning,
  91. ContainersPaused: cPaused,
  92. ContainersStopped: cStopped,
  93. Images: imageCount,
  94. Driver: drivers,
  95. DriverStatus: daemon.stores[p].layerStore.DriverStatus(),
  96. Plugins: daemon.showPluginsInfo(),
  97. IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled,
  98. BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled,
  99. BridgeNfIP6tables: !sysInfo.BridgeNFCallIP6TablesDisabled,
  100. Debug: debug.IsEnabled(),
  101. NFd: fileutils.GetTotalUsedFds(),
  102. NGoroutines: runtime.NumGoroutine(),
  103. SystemTime: time.Now().Format(time.RFC3339Nano),
  104. LoggingDriver: daemon.defaultLogConfig.Type,
  105. CgroupDriver: daemon.getCgroupDriver(),
  106. NEventsListener: daemon.EventsService.SubscribersCount(),
  107. KernelVersion: kernelVersion,
  108. OperatingSystem: operatingSystem,
  109. IndexServerAddress: registry.IndexServer,
  110. OSType: platform.OSType,
  111. Architecture: platform.Architecture,
  112. RegistryConfig: daemon.RegistryService.ServiceConfig(),
  113. NCPU: sysinfo.NumCPU(),
  114. MemTotal: meminfo.MemTotal,
  115. GenericResources: daemon.genericResources,
  116. DockerRootDir: daemon.configStore.Root,
  117. Labels: daemon.configStore.Labels,
  118. ExperimentalBuild: daemon.configStore.Experimental,
  119. ServerVersion: dockerversion.Version,
  120. ClusterStore: daemon.configStore.ClusterStore,
  121. ClusterAdvertise: daemon.configStore.ClusterAdvertise,
  122. HTTPProxy: sockets.GetProxyEnv("http_proxy"),
  123. HTTPSProxy: sockets.GetProxyEnv("https_proxy"),
  124. NoProxy: sockets.GetProxyEnv("no_proxy"),
  125. LiveRestoreEnabled: daemon.configStore.LiveRestoreEnabled,
  126. SecurityOptions: securityOptions,
  127. Isolation: daemon.defaultIsolation,
  128. }
  129. // Retrieve platform specific info
  130. daemon.FillPlatformInfo(v, sysInfo)
  131. hostname := ""
  132. if hn, err := os.Hostname(); err != nil {
  133. logrus.Warnf("Could not get hostname: %v", err)
  134. } else {
  135. hostname = hn
  136. }
  137. v.Name = hostname
  138. return v, nil
  139. }
  140. // SystemVersion returns version information about the daemon.
  141. func (daemon *Daemon) SystemVersion() types.Version {
  142. kernelVersion := "<unknown>"
  143. if kv, err := kernel.GetKernelVersion(); err != nil {
  144. logrus.Warnf("Could not get kernel version: %v", err)
  145. } else {
  146. kernelVersion = kv.String()
  147. }
  148. v := types.Version{
  149. Components: []types.ComponentVersion{
  150. {
  151. Name: "Engine",
  152. Version: dockerversion.Version,
  153. Details: map[string]string{
  154. "GitCommit": dockerversion.GitCommit,
  155. "ApiVersion": api.DefaultVersion,
  156. "MinAPIVersion": api.MinVersion,
  157. "GoVersion": runtime.Version(),
  158. "Os": runtime.GOOS,
  159. "Arch": runtime.GOARCH,
  160. "BuildTime": dockerversion.BuildTime,
  161. "KernelVersion": kernelVersion,
  162. "Experimental": fmt.Sprintf("%t", daemon.configStore.Experimental),
  163. },
  164. },
  165. },
  166. // Populate deprecated fields for older clients
  167. Version: dockerversion.Version,
  168. GitCommit: dockerversion.GitCommit,
  169. APIVersion: api.DefaultVersion,
  170. MinAPIVersion: api.MinVersion,
  171. GoVersion: runtime.Version(),
  172. Os: runtime.GOOS,
  173. Arch: runtime.GOARCH,
  174. BuildTime: dockerversion.BuildTime,
  175. KernelVersion: kernelVersion,
  176. Experimental: daemon.configStore.Experimental,
  177. }
  178. v.Platform.Name = dockerversion.PlatformName
  179. return v
  180. }
  181. func (daemon *Daemon) showPluginsInfo() types.PluginsInfo {
  182. var pluginsInfo types.PluginsInfo
  183. pluginsInfo.Volume = volumedrivers.GetDriverList()
  184. pluginsInfo.Network = daemon.GetNetworkDriverList()
  185. // The authorization plugins are returned in the order they are
  186. // used as they constitute a request/response modification chain.
  187. pluginsInfo.Authorization = daemon.configStore.AuthorizationPlugins
  188. pluginsInfo.Log = logger.ListDrivers()
  189. return pluginsInfo
  190. }