info.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package daemon
  2. import (
  3. "fmt"
  4. "os"
  5. "runtime"
  6. "time"
  7. "github.com/Sirupsen/logrus"
  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. )
  23. // SystemInfo returns information about the host server the daemon is running on.
  24. func (daemon *Daemon) SystemInfo() (*types.Info, error) {
  25. kernelVersion := "<unknown>"
  26. if kv, err := kernel.GetKernelVersion(); err != nil {
  27. logrus.Warnf("Could not get kernel version: %v", err)
  28. } else {
  29. kernelVersion = kv.String()
  30. }
  31. operatingSystem := "<unknown>"
  32. if s, err := operatingsystem.GetOperatingSystem(); err != nil {
  33. logrus.Warnf("Could not get operating system name: %v", err)
  34. } else {
  35. operatingSystem = s
  36. }
  37. // Don't do containerized check on Windows
  38. if runtime.GOOS != "windows" {
  39. if inContainer, err := operatingsystem.IsContainerized(); err != nil {
  40. logrus.Errorf("Could not determine if daemon is containerized: %v", err)
  41. operatingSystem += " (error determining if containerized)"
  42. } else if inContainer {
  43. operatingSystem += " (containerized)"
  44. }
  45. }
  46. meminfo, err := system.ReadMemInfo()
  47. if err != nil {
  48. logrus.Errorf("Could not read system memory info: %v", err)
  49. meminfo = &system.MemInfo{}
  50. }
  51. sysInfo := sysinfo.New(true)
  52. cRunning, cPaused, cStopped := stateCtr.get()
  53. securityOptions := []string{}
  54. if sysInfo.AppArmor {
  55. securityOptions = append(securityOptions, "name=apparmor")
  56. }
  57. if sysInfo.Seccomp && supportsSeccomp {
  58. profile := daemon.seccompProfilePath
  59. if profile == "" {
  60. profile = "default"
  61. }
  62. securityOptions = append(securityOptions, fmt.Sprintf("name=seccomp,profile=%s", profile))
  63. }
  64. if selinuxEnabled() {
  65. securityOptions = append(securityOptions, "name=selinux")
  66. }
  67. uid, gid := daemon.GetRemappedUIDGID()
  68. if uid != 0 || gid != 0 {
  69. securityOptions = append(securityOptions, "name=userns")
  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: debug.IsEnabled(),
  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: daemon.configStore.Experimental,
  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. LiveRestoreEnabled: daemon.configStore.LiveRestoreEnabled,
  109. SecurityOptions: securityOptions,
  110. Isolation: daemon.defaultIsolation,
  111. }
  112. // Retrieve platform specific info
  113. daemon.FillPlatformInfo(v, sysInfo)
  114. hostname := ""
  115. if hn, err := os.Hostname(); err != nil {
  116. logrus.Warnf("Could not get hostname: %v", err)
  117. } else {
  118. hostname = hn
  119. }
  120. v.Name = hostname
  121. return v, nil
  122. }
  123. // SystemVersion returns version information about the daemon.
  124. func (daemon *Daemon) SystemVersion() types.Version {
  125. v := types.Version{
  126. Version: dockerversion.Version,
  127. GitCommit: dockerversion.GitCommit,
  128. MinAPIVersion: api.MinVersion,
  129. GoVersion: runtime.Version(),
  130. Os: runtime.GOOS,
  131. Arch: runtime.GOARCH,
  132. BuildTime: dockerversion.BuildTime,
  133. Experimental: daemon.configStore.Experimental,
  134. }
  135. kernelVersion := "<unknown>"
  136. if kv, err := kernel.GetKernelVersion(); err != nil {
  137. logrus.Warnf("Could not get kernel version: %v", err)
  138. } else {
  139. kernelVersion = kv.String()
  140. }
  141. v.KernelVersion = kernelVersion
  142. return v
  143. }
  144. func (daemon *Daemon) showPluginsInfo() types.PluginsInfo {
  145. var pluginsInfo types.PluginsInfo
  146. pluginsInfo.Volume = volumedrivers.GetDriverList()
  147. pluginsInfo.Network = daemon.GetNetworkDriverList()
  148. // The authorization plugins are returned in the order they are
  149. // used as they constitute a request/response modification chain.
  150. pluginsInfo.Authorization = daemon.configStore.AuthorizationPlugins
  151. pluginsInfo.Log = logger.ListDrivers()
  152. return pluginsInfo
  153. }