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