daemon/info.go
94715e8e
 package daemon
 
 import (
 	"os"
 	"runtime"
3c82fad4
 	"sync/atomic"
2977fd2b
 	"time"
94715e8e
 
6f4d8470
 	"github.com/Sirupsen/logrus"
3c82fad4
 	"github.com/docker/docker/container"
8054a303
 	"github.com/docker/docker/dockerversion"
c30a55f1
 	"github.com/docker/docker/pkg/fileutils"
94715e8e
 	"github.com/docker/docker/pkg/parsers/kernel"
 	"github.com/docker/docker/pkg/parsers/operatingsystem"
49779b67
 	"github.com/docker/docker/pkg/platform"
b2d06b6f
 	"github.com/docker/docker/pkg/sysinfo"
61f8001c
 	"github.com/docker/docker/pkg/system"
94715e8e
 	"github.com/docker/docker/registry"
 	"github.com/docker/docker/utils"
aa7fd884
 	"github.com/docker/docker/volume/drivers"
907407d0
 	"github.com/docker/engine-api/types"
05002c25
 	"github.com/docker/go-connections/sockets"
94715e8e
 )
 
abd72d40
 // SystemInfo returns information about the host server the daemon is running on.
b08f071e
 func (daemon *Daemon) SystemInfo() (*types.Info, error) {
94715e8e
 	kernelVersion := "<unknown>"
b0fb0f19
 	if kv, err := kernel.GetKernelVersion(); err != nil {
 		logrus.Warnf("Could not get kernel version: %v", err)
 	} else {
94715e8e
 		kernelVersion = kv.String()
 	}
 
 	operatingSystem := "<unknown>"
b0fb0f19
 	if s, err := operatingsystem.GetOperatingSystem(); err != nil {
 		logrus.Warnf("Could not get operating system name: %v", err)
 	} else {
94715e8e
 		operatingSystem = s
 	}
ab97303c
 
 	// Don't do containerized check on Windows
 	if runtime.GOOS != "windows" {
 		if inContainer, err := operatingsystem.IsContainerized(); err != nil {
 			logrus.Errorf("Could not determine if daemon is containerized: %v", err)
 			operatingSystem += " (error determining if containerized)"
 		} else if inContainer {
 			operatingSystem += " (containerized)"
 		}
94715e8e
 	}
 
61f8001c
 	meminfo, err := system.ReadMemInfo()
 	if err != nil {
6f4d8470
 		logrus.Errorf("Could not read system memory info: %v", err)
61f8001c
 	}
 
aaacde4f
 	sysInfo := sysinfo.New(true)
b2d06b6f
 
3c82fad4
 	var cRunning, cPaused, cStopped int32
 	daemon.containers.ApplyAll(func(c *container.Container) {
e732f4e6
 		switch c.StateString() {
 		case "paused":
3c82fad4
 			atomic.AddInt32(&cPaused, 1)
e732f4e6
 		case "running":
3c82fad4
 			atomic.AddInt32(&cRunning, 1)
e732f4e6
 		default:
3c82fad4
 			atomic.AddInt32(&cStopped, 1)
e732f4e6
 		}
3c82fad4
 	})
e732f4e6
 
190654aa
 	var securityOptions []string
 	if sysInfo.AppArmor {
 		securityOptions = append(securityOptions, "apparmor")
 	}
 	if sysInfo.Seccomp {
 		securityOptions = append(securityOptions, "seccomp")
 	}
 	if selinuxEnabled() {
 		securityOptions = append(securityOptions, "selinux")
 	}
 
f4942ed8
 	v := &types.Info{
 		ID:                 daemon.ID,
3c82fad4
 		Containers:         int(cRunning + cPaused + cStopped),
 		ContainersRunning:  int(cRunning),
 		ContainersPaused:   int(cPaused),
 		ContainersStopped:  int(cStopped),
4352da78
 		Images:             len(daemon.imageStore.Map()),
f5916b10
 		Driver:             daemon.GraphDriverName(),
 		DriverStatus:       daemon.layerStore.DriverStatus(),
aa7fd884
 		Plugins:            daemon.showPluginsInfo(),
b2d06b6f
 		IPv4Forwarding:     !sysInfo.IPv4ForwardingDisabled,
5b3fc7aa
 		BridgeNfIptables:   !sysInfo.BridgeNFCallIPTablesDisabled,
 		BridgeNfIP6tables:  !sysInfo.BridgeNFCallIP6TablesDisabled,
677a6b35
 		Debug:              utils.IsDebugEnabled(),
f4942ed8
 		NFd:                fileutils.GetTotalUsedFds(),
 		NGoroutines:        runtime.NumGoroutine(),
 		SystemTime:         time.Now().Format(time.RFC3339Nano),
 		LoggingDriver:      daemon.defaultLogConfig.Type,
ca89c329
 		CgroupDriver:       daemon.getCgroupDriver(),
f4942ed8
 		NEventsListener:    daemon.EventsService.SubscribersCount(),
 		KernelVersion:      kernelVersion,
 		OperatingSystem:    operatingSystem,
4fcb9ac4
 		IndexServerAddress: registry.IndexServer,
49779b67
 		OSType:             platform.OSType,
 		Architecture:       platform.Architecture,
59586d02
 		RegistryConfig:     daemon.RegistryService.ServiceConfig(),
f4942ed8
 		NCPU:               runtime.NumCPU(),
 		MemTotal:           meminfo.MemTotal,
3662f580
 		DockerRootDir:      daemon.configStore.Root,
 		Labels:             daemon.configStore.Labels,
ca6722f1
 		ExperimentalBuild:  utils.ExperimentalBuild(),
8054a303
 		ServerVersion:      dockerversion.Version,
3662f580
 		ClusterStore:       daemon.configStore.ClusterStore,
 		ClusterAdvertise:   daemon.configStore.ClusterAdvertise,
05002c25
 		HTTPProxy:          sockets.GetProxyEnv("http_proxy"),
 		HTTPSProxy:         sockets.GetProxyEnv("https_proxy"),
 		NoProxy:            sockets.GetProxyEnv("no_proxy"),
190654aa
 		SecurityOptions:    securityOptions,
f4942ed8
 	}
 
4348ad68
 	// TODO Windows. Refactor this more once sysinfo is refactored into
 	// platform specific code. On Windows, sysinfo.cgroupMemInfo and
 	// sysinfo.cgroupCpuInfo will be nil otherwise and cause a SIGSEGV if
 	// an attempt is made to access through them.
 	if runtime.GOOS != "windows" {
b2d06b6f
 		v.MemoryLimit = sysInfo.MemoryLimit
 		v.SwapLimit = sysInfo.SwapLimit
747a486b
 		v.KernelMemory = sysInfo.KernelMemory
b2d06b6f
 		v.OomKillDisable = sysInfo.OomKillDisable
3d6617ff
 		v.CPUCfsPeriod = sysInfo.CPUCfsPeriod
 		v.CPUCfsQuota = sysInfo.CPUCfsQuota
458ec418
 		v.CPUShares = sysInfo.CPUShares
 		v.CPUSet = sysInfo.Cpuset
7b2e5216
 		v.Runtimes = daemon.configStore.GetAllRuntimes()
 		v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName()
4348ad68
 	}
 
a1c95091
 	hostname := ""
 	if hn, err := os.Hostname(); err != nil {
 		logrus.Warnf("Could not get hostname: %v", err)
 	} else {
 		hostname = hn
9a85f60c
 	}
a1c95091
 	v.Name = hostname
f4942ed8
 
 	return v, nil
94715e8e
 }
aa7fd884
 
867f4329
 // SystemVersion returns version information about the daemon.
 func (daemon *Daemon) SystemVersion() types.Version {
 	v := types.Version{
 		Version:      dockerversion.Version,
 		GitCommit:    dockerversion.GitCommit,
 		GoVersion:    runtime.Version(),
 		Os:           runtime.GOOS,
 		Arch:         runtime.GOARCH,
 		BuildTime:    dockerversion.BuildTime,
 		Experimental: utils.ExperimentalBuild(),
 	}
 
73046cb8
 	kernelVersion := "<unknown>"
 	if kv, err := kernel.GetKernelVersion(); err != nil {
 		logrus.Warnf("Could not get kernel version: %v", err)
 	} else {
 		kernelVersion = kv.String()
867f4329
 	}
73046cb8
 	v.KernelVersion = kernelVersion
867f4329
 
 	return v
 }
 
aa7fd884
 func (daemon *Daemon) showPluginsInfo() types.PluginsInfo {
 	var pluginsInfo types.PluginsInfo
 
 	pluginsInfo.Volume = volumedrivers.GetDriverList()
 
 	networkDriverList := daemon.GetNetworkDriverList()
 	for nd := range networkDriverList {
 		pluginsInfo.Network = append(pluginsInfo.Network, nd)
 	}
 
5c630ea7
 	pluginsInfo.Authorization = daemon.configStore.AuthorizationPlugins
4a1eb3f3
 
aa7fd884
 	return pluginsInfo
 }