github.com/squaremo/docker@v1.3.2-0.20150516120342-42cfc9554972/daemon/info.go (about) 1 package daemon 2 3 import ( 4 "os" 5 "runtime" 6 "time" 7 8 "github.com/Sirupsen/logrus" 9 "github.com/docker/docker/api/types" 10 "github.com/docker/docker/autogen/dockerversion" 11 "github.com/docker/docker/pkg/fileutils" 12 "github.com/docker/docker/pkg/parsers/kernel" 13 "github.com/docker/docker/pkg/parsers/operatingsystem" 14 "github.com/docker/docker/pkg/system" 15 "github.com/docker/docker/registry" 16 "github.com/docker/docker/utils" 17 ) 18 19 func (daemon *Daemon) SystemInfo() (*types.Info, error) { 20 images, _ := daemon.Graph().Map() 21 var imgcount int 22 if images == nil { 23 imgcount = 0 24 } else { 25 imgcount = len(images) 26 } 27 kernelVersion := "<unknown>" 28 if kv, err := kernel.GetKernelVersion(); err == nil { 29 kernelVersion = kv.String() 30 } 31 32 operatingSystem := "<unknown>" 33 if s, err := operatingsystem.GetOperatingSystem(); err == nil { 34 operatingSystem = s 35 } 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 47 meminfo, err := system.ReadMemInfo() 48 if err != nil { 49 logrus.Errorf("Could not read system memory info: %v", err) 50 } 51 52 // if we still have the original dockerinit binary from before we copied it locally, let's return the path to that, since that's more intuitive (the copied path is trivial to derive by hand given VERSION) 53 initPath := utils.DockerInitPath("") 54 if initPath == "" { 55 // if that fails, we'll just return the path from the daemon 56 initPath = daemon.SystemInitPath() 57 } 58 59 v := &types.Info{ 60 ID: daemon.ID, 61 Containers: len(daemon.List()), 62 Images: imgcount, 63 Driver: daemon.GraphDriver().String(), 64 DriverStatus: daemon.GraphDriver().Status(), 65 MemoryLimit: daemon.SystemConfig().MemoryLimit, 66 SwapLimit: daemon.SystemConfig().SwapLimit, 67 CpuCfsPeriod: daemon.SystemConfig().CpuCfsPeriod, 68 CpuCfsQuota: daemon.SystemConfig().CpuCfsQuota, 69 IPv4Forwarding: !daemon.SystemConfig().IPv4ForwardingDisabled, 70 Debug: os.Getenv("DEBUG") != "", 71 NFd: fileutils.GetTotalUsedFds(), 72 OomKillDisable: daemon.SystemConfig().OomKillDisable, 73 NGoroutines: runtime.NumGoroutine(), 74 SystemTime: time.Now().Format(time.RFC3339Nano), 75 ExecutionDriver: daemon.ExecutionDriver().Name(), 76 LoggingDriver: daemon.defaultLogConfig.Type, 77 NEventsListener: daemon.EventsService.SubscribersCount(), 78 KernelVersion: kernelVersion, 79 OperatingSystem: operatingSystem, 80 IndexServerAddress: registry.IndexServerAddress(), 81 RegistryConfig: daemon.RegistryService.Config, 82 InitSha1: dockerversion.INITSHA1, 83 InitPath: initPath, 84 NCPU: runtime.NumCPU(), 85 MemTotal: meminfo.MemTotal, 86 DockerRootDir: daemon.Config().Root, 87 Labels: daemon.Config().Labels, 88 } 89 90 if httpProxy := os.Getenv("http_proxy"); httpProxy != "" { 91 v.HttpProxy = httpProxy 92 } 93 if httpsProxy := os.Getenv("https_proxy"); httpsProxy != "" { 94 v.HttpsProxy = httpsProxy 95 } 96 if noProxy := os.Getenv("no_proxy"); noProxy != "" { 97 v.NoProxy = noProxy 98 } 99 if hostname, err := os.Hostname(); err == nil { 100 v.Name = hostname 101 } 102 103 return v, nil 104 }