info.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. v := types.Version{
  143. Version: dockerversion.Version,
  144. GitCommit: dockerversion.GitCommit,
  145. MinAPIVersion: api.MinVersion,
  146. GoVersion: runtime.Version(),
  147. Os: runtime.GOOS,
  148. Arch: runtime.GOARCH,
  149. BuildTime: dockerversion.BuildTime,
  150. Experimental: daemon.configStore.Experimental,
  151. }
  152. kernelVersion := "<unknown>"
  153. if kv, err := kernel.GetKernelVersion(); err != nil {
  154. logrus.Warnf("Could not get kernel version: %v", err)
  155. } else {
  156. kernelVersion = kv.String()
  157. }
  158. v.KernelVersion = kernelVersion
  159. return v
  160. }
  161. func (daemon *Daemon) showPluginsInfo() types.PluginsInfo {
  162. var pluginsInfo types.PluginsInfo
  163. pluginsInfo.Volume = volumedrivers.GetDriverList()
  164. pluginsInfo.Network = daemon.GetNetworkDriverList()
  165. // The authorization plugins are returned in the order they are
  166. // used as they constitute a request/response modification chain.
  167. pluginsInfo.Authorization = daemon.configStore.AuthorizationPlugins
  168. pluginsInfo.Log = logger.ListDrivers()
  169. return pluginsInfo
  170. }