github.com/kunnos/engine@v1.13.1/daemon/info.go (about)

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