github.com/kim0/docker@v0.6.2-0.20161130212042-4addda3f07e7/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/api/types"
    11  	"github.com/docker/docker/container"
    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/utils"
    21  	"github.com/docker/docker/volume/drivers"
    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  		meminfo = &system.MemInfo{}
    55  	}
    56  
    57  	sysInfo := sysinfo.New(true)
    58  
    59  	var cRunning, cPaused, cStopped int32
    60  	daemon.containers.ApplyAll(func(c *container.Container) {
    61  		switch c.StateString() {
    62  		case "paused":
    63  			atomic.AddInt32(&cPaused, 1)
    64  		case "running":
    65  			atomic.AddInt32(&cRunning, 1)
    66  		default:
    67  			atomic.AddInt32(&cStopped, 1)
    68  		}
    69  	})
    70  
    71  	var securityOptions []string
    72  	if sysInfo.AppArmor {
    73  		securityOptions = append(securityOptions, "apparmor")
    74  	}
    75  	if sysInfo.Seccomp && supportsSeccomp {
    76  		securityOptions = append(securityOptions, "seccomp")
    77  	}
    78  	if selinuxEnabled() {
    79  		securityOptions = append(securityOptions, "selinux")
    80  	}
    81  	uid, gid := daemon.GetRemappedUIDGID()
    82  	if uid != 0 || gid != 0 {
    83  		securityOptions = append(securityOptions, "userns")
    84  	}
    85  
    86  	v := &types.Info{
    87  		ID:                 daemon.ID,
    88  		Containers:         int(cRunning + cPaused + cStopped),
    89  		ContainersRunning:  int(cRunning),
    90  		ContainersPaused:   int(cPaused),
    91  		ContainersStopped:  int(cStopped),
    92  		Images:             len(daemon.imageStore.Map()),
    93  		Driver:             daemon.GraphDriverName(),
    94  		DriverStatus:       daemon.layerStore.DriverStatus(),
    95  		Plugins:            daemon.showPluginsInfo(),
    96  		IPv4Forwarding:     !sysInfo.IPv4ForwardingDisabled,
    97  		BridgeNfIptables:   !sysInfo.BridgeNFCallIPTablesDisabled,
    98  		BridgeNfIP6tables:  !sysInfo.BridgeNFCallIP6TablesDisabled,
    99  		Debug:              utils.IsDebugEnabled(),
   100  		NFd:                fileutils.GetTotalUsedFds(),
   101  		NGoroutines:        runtime.NumGoroutine(),
   102  		SystemTime:         time.Now().Format(time.RFC3339Nano),
   103  		LoggingDriver:      daemon.defaultLogConfig.Type,
   104  		CgroupDriver:       daemon.getCgroupDriver(),
   105  		NEventsListener:    daemon.EventsService.SubscribersCount(),
   106  		KernelVersion:      kernelVersion,
   107  		OperatingSystem:    operatingSystem,
   108  		IndexServerAddress: registry.IndexServer,
   109  		OSType:             platform.OSType,
   110  		Architecture:       platform.Architecture,
   111  		RegistryConfig:     daemon.RegistryService.ServiceConfig(),
   112  		NCPU:               sysinfo.NumCPU(),
   113  		MemTotal:           meminfo.MemTotal,
   114  		DockerRootDir:      daemon.configStore.Root,
   115  		Labels:             daemon.configStore.Labels,
   116  		ExperimentalBuild:  daemon.configStore.Experimental,
   117  		ServerVersion:      dockerversion.Version,
   118  		ClusterStore:       daemon.configStore.ClusterStore,
   119  		ClusterAdvertise:   daemon.configStore.ClusterAdvertise,
   120  		HTTPProxy:          sockets.GetProxyEnv("http_proxy"),
   121  		HTTPSProxy:         sockets.GetProxyEnv("https_proxy"),
   122  		NoProxy:            sockets.GetProxyEnv("no_proxy"),
   123  		SecurityOptions:    securityOptions,
   124  		LiveRestoreEnabled: daemon.configStore.LiveRestoreEnabled,
   125  		Isolation:          daemon.defaultIsolation,
   126  	}
   127  
   128  	// TODO Windows. Refactor this more once sysinfo is refactored into
   129  	// platform specific code. On Windows, sysinfo.cgroupMemInfo and
   130  	// sysinfo.cgroupCpuInfo will be nil otherwise and cause a SIGSEGV if
   131  	// an attempt is made to access through them.
   132  	if runtime.GOOS != "windows" {
   133  		v.MemoryLimit = sysInfo.MemoryLimit
   134  		v.SwapLimit = sysInfo.SwapLimit
   135  		v.KernelMemory = sysInfo.KernelMemory
   136  		v.OomKillDisable = sysInfo.OomKillDisable
   137  		v.CPUCfsPeriod = sysInfo.CPUCfsPeriod
   138  		v.CPUCfsQuota = sysInfo.CPUCfsQuota
   139  		v.CPUShares = sysInfo.CPUShares
   140  		v.CPUSet = sysInfo.Cpuset
   141  		v.Runtimes = daemon.configStore.GetAllRuntimes()
   142  		v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName()
   143  	}
   144  
   145  	hostname := ""
   146  	if hn, err := os.Hostname(); err != nil {
   147  		logrus.Warnf("Could not get hostname: %v", err)
   148  	} else {
   149  		hostname = hn
   150  	}
   151  	v.Name = hostname
   152  
   153  	return v, nil
   154  }
   155  
   156  // SystemVersion returns version information about the daemon.
   157  func (daemon *Daemon) SystemVersion() types.Version {
   158  	v := types.Version{
   159  		Version:      dockerversion.Version,
   160  		GitCommit:    dockerversion.GitCommit,
   161  		GoVersion:    runtime.Version(),
   162  		Os:           runtime.GOOS,
   163  		Arch:         runtime.GOARCH,
   164  		BuildTime:    dockerversion.BuildTime,
   165  		Experimental: daemon.configStore.Experimental,
   166  	}
   167  
   168  	kernelVersion := "<unknown>"
   169  	if kv, err := kernel.GetKernelVersion(); err != nil {
   170  		logrus.Warnf("Could not get kernel version: %v", err)
   171  	} else {
   172  		kernelVersion = kv.String()
   173  	}
   174  	v.KernelVersion = kernelVersion
   175  
   176  	return v
   177  }
   178  
   179  func (daemon *Daemon) showPluginsInfo() types.PluginsInfo {
   180  	var pluginsInfo types.PluginsInfo
   181  
   182  	pluginsInfo.Volume = volumedrivers.GetDriverList()
   183  	pluginsInfo.Network = daemon.GetNetworkDriverList()
   184  	pluginsInfo.Authorization = daemon.configStore.AuthorizationPlugins
   185  
   186  	return pluginsInfo
   187  }