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