github.com/uppal0016/docker_new@v0.0.0-20240123060250-1c98be13ac2c/daemon/info.go (about) 1 package daemon 2 3 import ( 4 "os" 5 "runtime" 6 "sync/atomic" 7 "time" 8 9 "github.com/Sirupsen/logrus" 10 "github.com/docker/docker/container" 11 "github.com/docker/docker/dockerversion" 12 "github.com/docker/docker/pkg/fileutils" 13 "github.com/docker/docker/pkg/parsers/kernel" 14 "github.com/docker/docker/pkg/parsers/operatingsystem" 15 "github.com/docker/docker/pkg/platform" 16 "github.com/docker/docker/pkg/sysinfo" 17 "github.com/docker/docker/pkg/system" 18 "github.com/docker/docker/registry" 19 "github.com/docker/docker/utils" 20 "github.com/docker/docker/volume/drivers" 21 "github.com/docker/engine-api/types" 22 "github.com/docker/go-connections/sockets" 23 ) 24 25 // SystemInfo returns information about the host server the daemon is running on. 26 func (daemon *Daemon) SystemInfo() (*types.Info, error) { 27 kernelVersion := "<unknown>" 28 if kv, err := kernel.GetKernelVersion(); err != nil { 29 logrus.Warnf("Could not get kernel version: %v", err) 30 } else { 31 kernelVersion = kv.String() 32 } 33 34 operatingSystem := "<unknown>" 35 if s, err := operatingsystem.GetOperatingSystem(); err != nil { 36 logrus.Warnf("Could not get operating system name: %v", err) 37 } else { 38 operatingSystem = s 39 } 40 41 // Don't do containerized check on Windows 42 if runtime.GOOS != "windows" { 43 if inContainer, err := operatingsystem.IsContainerized(); err != nil { 44 logrus.Errorf("Could not determine if daemon is containerized: %v", err) 45 operatingSystem += " (error determining if containerized)" 46 } else if inContainer { 47 operatingSystem += " (containerized)" 48 } 49 } 50 51 meminfo, err := system.ReadMemInfo() 52 if err != nil { 53 logrus.Errorf("Could not read system memory info: %v", err) 54 } 55 56 sysInfo := sysinfo.New(true) 57 58 var cRunning, cPaused, cStopped int32 59 daemon.containers.ApplyAll(func(c *container.Container) { 60 switch c.StateString() { 61 case "paused": 62 atomic.AddInt32(&cPaused, 1) 63 case "running": 64 atomic.AddInt32(&cRunning, 1) 65 default: 66 atomic.AddInt32(&cStopped, 1) 67 } 68 }) 69 70 v := &types.Info{ 71 ID: daemon.ID, 72 Containers: int(cRunning + cPaused + cStopped), 73 ContainersRunning: int(cRunning), 74 ContainersPaused: int(cPaused), 75 ContainersStopped: int(cStopped), 76 Images: len(daemon.imageStore.Map()), 77 Driver: daemon.GraphDriverName(), 78 DriverStatus: daemon.layerStore.DriverStatus(), 79 Plugins: daemon.showPluginsInfo(), 80 IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled, 81 BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled, 82 BridgeNfIP6tables: !sysInfo.BridgeNFCallIP6TablesDisabled, 83 Debug: utils.IsDebugEnabled(), 84 NFd: fileutils.GetTotalUsedFds(), 85 NGoroutines: runtime.NumGoroutine(), 86 SystemTime: time.Now().Format(time.RFC3339Nano), 87 LoggingDriver: daemon.defaultLogConfig.Type, 88 CgroupDriver: daemon.getCgroupDriver(), 89 NEventsListener: daemon.EventsService.SubscribersCount(), 90 KernelVersion: kernelVersion, 91 OperatingSystem: operatingSystem, 92 IndexServerAddress: registry.IndexServer, 93 OSType: platform.OSType, 94 Architecture: platform.Architecture, 95 RegistryConfig: daemon.RegistryService.ServiceConfig(), 96 NCPU: runtime.NumCPU(), 97 MemTotal: meminfo.MemTotal, 98 DockerRootDir: daemon.configStore.Root, 99 Labels: daemon.configStore.Labels, 100 ExperimentalBuild: utils.ExperimentalBuild(), 101 ServerVersion: dockerversion.Version, 102 ClusterStore: daemon.configStore.ClusterStore, 103 ClusterAdvertise: daemon.configStore.ClusterAdvertise, 104 HTTPProxy: sockets.GetProxyEnv("http_proxy"), 105 HTTPSProxy: sockets.GetProxyEnv("https_proxy"), 106 NoProxy: sockets.GetProxyEnv("no_proxy"), 107 } 108 109 // TODO Windows. Refactor this more once sysinfo is refactored into 110 // platform specific code. On Windows, sysinfo.cgroupMemInfo and 111 // sysinfo.cgroupCpuInfo will be nil otherwise and cause a SIGSEGV if 112 // an attempt is made to access through them. 113 if runtime.GOOS != "windows" { 114 v.MemoryLimit = sysInfo.MemoryLimit 115 v.SwapLimit = sysInfo.SwapLimit 116 v.KernelMemory = sysInfo.KernelMemory 117 v.OomKillDisable = sysInfo.OomKillDisable 118 v.CPUCfsPeriod = sysInfo.CPUCfsPeriod 119 v.CPUCfsQuota = sysInfo.CPUCfsQuota 120 v.CPUShares = sysInfo.CPUShares 121 v.CPUSet = sysInfo.Cpuset 122 } 123 124 if hostname, err := os.Hostname(); err == nil { 125 v.Name = hostname 126 } 127 128 return v, nil 129 } 130 131 // SystemVersion returns version information about the daemon. 132 func (daemon *Daemon) SystemVersion() types.Version { 133 v := types.Version{ 134 Version: dockerversion.Version, 135 GitCommit: dockerversion.GitCommit, 136 GoVersion: runtime.Version(), 137 Os: runtime.GOOS, 138 Arch: runtime.GOARCH, 139 BuildTime: dockerversion.BuildTime, 140 Experimental: utils.ExperimentalBuild(), 141 } 142 143 kernelVersion := "<unknown>" 144 if kv, err := kernel.GetKernelVersion(); err != nil { 145 logrus.Warnf("Could not get kernel version: %v", err) 146 } else { 147 kernelVersion = kv.String() 148 } 149 v.KernelVersion = kernelVersion 150 151 return v 152 } 153 154 func (daemon *Daemon) showPluginsInfo() types.PluginsInfo { 155 var pluginsInfo types.PluginsInfo 156 157 pluginsInfo.Volume = volumedrivers.GetDriverList() 158 159 networkDriverList := daemon.GetNetworkDriverList() 160 for nd := range networkDriverList { 161 pluginsInfo.Network = append(pluginsInfo.Network, nd) 162 } 163 164 pluginsInfo.Authorization = daemon.configStore.AuthorizationPlugins 165 166 return pluginsInfo 167 }