github.com/jiasir/docker@v1.3.3-0.20170609024000-252e610103e7/daemon/info.go (about)

     1  package daemon
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"runtime"
     7  	"time"
     8  
     9  	"github.com/Sirupsen/logrus"
    10  	"github.com/docker/docker/api"
    11  	"github.com/docker/docker/api/types"
    12  	"github.com/docker/docker/cli/debug"
    13  	"github.com/docker/docker/daemon/logger"
    14  	"github.com/docker/docker/dockerversion"
    15  	"github.com/docker/docker/pkg/fileutils"
    16  	"github.com/docker/docker/pkg/parsers/kernel"
    17  	"github.com/docker/docker/pkg/parsers/operatingsystem"
    18  	"github.com/docker/docker/pkg/platform"
    19  	"github.com/docker/docker/pkg/sysinfo"
    20  	"github.com/docker/docker/pkg/system"
    21  	"github.com/docker/docker/registry"
    22  	"github.com/docker/docker/volume/drivers"
    23  	"github.com/docker/go-connections/sockets"
    24  )
    25  
    26  // SystemInfo returns information about the host server the daemon is running on.
    27  func (daemon *Daemon) SystemInfo() (*types.Info, error) {
    28  	kernelVersion := "<unknown>"
    29  	if kv, err := kernel.GetKernelVersion(); err != nil {
    30  		logrus.Warnf("Could not get kernel version: %v", err)
    31  	} else {
    32  		kernelVersion = kv.String()
    33  	}
    34  
    35  	operatingSystem := "<unknown>"
    36  	if s, err := operatingsystem.GetOperatingSystem(); err != nil {
    37  		logrus.Warnf("Could not get operating system name: %v", err)
    38  	} else {
    39  		operatingSystem = s
    40  	}
    41  
    42  	// Don't do containerized check on Windows
    43  	if runtime.GOOS != "windows" {
    44  		if inContainer, err := operatingsystem.IsContainerized(); err != nil {
    45  			logrus.Errorf("Could not determine if daemon is containerized: %v", err)
    46  			operatingSystem += " (error determining if containerized)"
    47  		} else if inContainer {
    48  			operatingSystem += " (containerized)"
    49  		}
    50  	}
    51  
    52  	meminfo, err := system.ReadMemInfo()
    53  	if err != nil {
    54  		logrus.Errorf("Could not read system memory info: %v", err)
    55  		meminfo = &system.MemInfo{}
    56  	}
    57  
    58  	sysInfo := sysinfo.New(true)
    59  	cRunning, cPaused, cStopped := stateCtr.get()
    60  
    61  	securityOptions := []string{}
    62  	if sysInfo.AppArmor {
    63  		securityOptions = append(securityOptions, "name=apparmor")
    64  	}
    65  	if sysInfo.Seccomp && supportsSeccomp {
    66  		profile := daemon.seccompProfilePath
    67  		if profile == "" {
    68  			profile = "default"
    69  		}
    70  		securityOptions = append(securityOptions, fmt.Sprintf("name=seccomp,profile=%s", profile))
    71  	}
    72  	if selinuxEnabled() {
    73  		securityOptions = append(securityOptions, "name=selinux")
    74  	}
    75  	rootIDs := daemon.idMappings.RootPair()
    76  	if rootIDs.UID != 0 || rootIDs.GID != 0 {
    77  		securityOptions = append(securityOptions, "name=userns")
    78  	}
    79  
    80  	v := &types.Info{
    81  		ID:                 daemon.ID,
    82  		Containers:         int(cRunning + cPaused + cStopped),
    83  		ContainersRunning:  int(cRunning),
    84  		ContainersPaused:   int(cPaused),
    85  		ContainersStopped:  int(cStopped),
    86  		Images:             len(daemon.imageStore.Map()),
    87  		Driver:             daemon.GraphDriverName(),
    88  		DriverStatus:       daemon.layerStore.DriverStatus(),
    89  		Plugins:            daemon.showPluginsInfo(),
    90  		IPv4Forwarding:     !sysInfo.IPv4ForwardingDisabled,
    91  		BridgeNfIptables:   !sysInfo.BridgeNFCallIPTablesDisabled,
    92  		BridgeNfIP6tables:  !sysInfo.BridgeNFCallIP6TablesDisabled,
    93  		Debug:              debug.IsEnabled(),
    94  		NFd:                fileutils.GetTotalUsedFds(),
    95  		NGoroutines:        runtime.NumGoroutine(),
    96  		SystemTime:         time.Now().Format(time.RFC3339Nano),
    97  		LoggingDriver:      daemon.defaultLogConfig.Type,
    98  		CgroupDriver:       daemon.getCgroupDriver(),
    99  		NEventsListener:    daemon.EventsService.SubscribersCount(),
   100  		KernelVersion:      kernelVersion,
   101  		OperatingSystem:    operatingSystem,
   102  		IndexServerAddress: registry.IndexServer,
   103  		OSType:             platform.OSType,
   104  		Architecture:       platform.Architecture,
   105  		RegistryConfig:     daemon.RegistryService.ServiceConfig(),
   106  		NCPU:               sysinfo.NumCPU(),
   107  		MemTotal:           meminfo.MemTotal,
   108  		DockerRootDir:      daemon.configStore.Root,
   109  		Labels:             daemon.configStore.Labels,
   110  		ExperimentalBuild:  daemon.configStore.Experimental,
   111  		ServerVersion:      dockerversion.Version,
   112  		ClusterStore:       daemon.configStore.ClusterStore,
   113  		ClusterAdvertise:   daemon.configStore.ClusterAdvertise,
   114  		HTTPProxy:          sockets.GetProxyEnv("http_proxy"),
   115  		HTTPSProxy:         sockets.GetProxyEnv("https_proxy"),
   116  		NoProxy:            sockets.GetProxyEnv("no_proxy"),
   117  		LiveRestoreEnabled: daemon.configStore.LiveRestoreEnabled,
   118  		SecurityOptions:    securityOptions,
   119  		Isolation:          daemon.defaultIsolation,
   120  	}
   121  
   122  	// Retrieve platform specific info
   123  	daemon.FillPlatformInfo(v, sysInfo)
   124  
   125  	hostname := ""
   126  	if hn, err := os.Hostname(); err != nil {
   127  		logrus.Warnf("Could not get hostname: %v", err)
   128  	} else {
   129  		hostname = hn
   130  	}
   131  	v.Name = hostname
   132  
   133  	return v, nil
   134  }
   135  
   136  // SystemVersion returns version information about the daemon.
   137  func (daemon *Daemon) SystemVersion() types.Version {
   138  	v := types.Version{
   139  		Version:       dockerversion.Version,
   140  		GitCommit:     dockerversion.GitCommit,
   141  		MinAPIVersion: api.MinVersion,
   142  		GoVersion:     runtime.Version(),
   143  		Os:            runtime.GOOS,
   144  		Arch:          runtime.GOARCH,
   145  		BuildTime:     dockerversion.BuildTime,
   146  		Experimental:  daemon.configStore.Experimental,
   147  	}
   148  
   149  	kernelVersion := "<unknown>"
   150  	if kv, err := kernel.GetKernelVersion(); err != nil {
   151  		logrus.Warnf("Could not get kernel version: %v", err)
   152  	} else {
   153  		kernelVersion = kv.String()
   154  	}
   155  	v.KernelVersion = kernelVersion
   156  
   157  	return v
   158  }
   159  
   160  func (daemon *Daemon) showPluginsInfo() types.PluginsInfo {
   161  	var pluginsInfo types.PluginsInfo
   162  
   163  	pluginsInfo.Volume = volumedrivers.GetDriverList()
   164  	pluginsInfo.Network = daemon.GetNetworkDriverList()
   165  	// The authorization plugins are returned in the order they are
   166  	// used as they constitute a request/response modification chain.
   167  	pluginsInfo.Authorization = daemon.configStore.AuthorizationPlugins
   168  	pluginsInfo.Log = logger.ListDrivers()
   169  
   170  	return pluginsInfo
   171  }