Kaynağa Gözat

daemon: SystemInfo() extract collecting debugging information to a helper

This makes it more inline with other data we collect, and can be used to make
some info optional at some point.

fillDebugInfo sets the current debugging state of the daemon, and additional
debugging information, such as the number of Go-routines, and file descriptors.

Note that this currently always collects the information, but the CLI only
prints it if the daemon has debug enabled. We should consider to either make
this information optional (cli to request "with debugging information"), or
only collect it if the daemon has debug enabled. For the CLI code, see
https://github.com/docker/cli/blob/v20.10.12/cli/command/system/info.go#L239-L244

Additional note: the CLI considers info.SystemTime debugging information. This
felt a bit "odd" (daemon time could be useful for standard use), so I left this
out of this function.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 3 yıl önce
ebeveyn
işleme
d492101172
1 değiştirilmiş dosya ile 16 ekleme ve 4 silme
  1. 16 4
      daemon/info.go

+ 16 - 4
daemon/info.go

@@ -37,13 +37,9 @@ func (daemon *Daemon) SystemInfo() *types.Info {
 		IPv4Forwarding:     !sysInfo.IPv4ForwardingDisabled,
 		IPv4Forwarding:     !sysInfo.IPv4ForwardingDisabled,
 		BridgeNfIptables:   !sysInfo.BridgeNFCallIPTablesDisabled,
 		BridgeNfIptables:   !sysInfo.BridgeNFCallIPTablesDisabled,
 		BridgeNfIP6tables:  !sysInfo.BridgeNFCallIP6TablesDisabled,
 		BridgeNfIP6tables:  !sysInfo.BridgeNFCallIP6TablesDisabled,
-		Debug:              debug.IsEnabled(),
 		Name:               hostName(),
 		Name:               hostName(),
-		NFd:                fileutils.GetTotalUsedFds(),
-		NGoroutines:        runtime.NumGoroutine(),
 		SystemTime:         time.Now().Format(time.RFC3339Nano),
 		SystemTime:         time.Now().Format(time.RFC3339Nano),
 		LoggingDriver:      daemon.defaultLogConfig.Type,
 		LoggingDriver:      daemon.defaultLogConfig.Type,
-		NEventsListener:    daemon.EventsService.SubscribersCount(),
 		KernelVersion:      kernelVersion(),
 		KernelVersion:      kernelVersion(),
 		OperatingSystem:    operatingSystem(),
 		OperatingSystem:    operatingSystem(),
 		OSVersion:          osVersion(),
 		OSVersion:          osVersion(),
@@ -66,6 +62,7 @@ func (daemon *Daemon) SystemInfo() *types.Info {
 	}
 	}
 
 
 	daemon.fillContainerStates(v)
 	daemon.fillContainerStates(v)
+	daemon.fillDebugInfo(v)
 	daemon.fillAPIInfo(v)
 	daemon.fillAPIInfo(v)
 	// Retrieve platform specific info
 	// Retrieve platform specific info
 	daemon.fillPlatformInfo(v, sysInfo)
 	daemon.fillPlatformInfo(v, sysInfo)
@@ -185,6 +182,21 @@ func (daemon *Daemon) fillContainerStates(v *types.Info) {
 	v.ContainersStopped = cStopped
 	v.ContainersStopped = cStopped
 }
 }
 
 
+// fillDebugInfo sets the current debugging state of the daemon, and additional
+// debugging information, such as the number of Go-routines, and file descriptors.
+//
+// Note that this currently always collects the information, but the CLI only
+// prints it if the daemon has debug enabled. We should consider to either make
+// this information optional (cli to request "with debugging information"), or
+// only collect it if the daemon has debug enabled. For the CLI code, see
+// https://github.com/docker/cli/blob/v20.10.12/cli/command/system/info.go#L239-L244
+func (daemon *Daemon) fillDebugInfo(v *types.Info) {
+	v.Debug = debug.IsEnabled()
+	v.NFd = fileutils.GetTotalUsedFds()
+	v.NGoroutines = runtime.NumGoroutine()
+	v.NEventsListener = daemon.EventsService.SubscribersCount()
+}
+
 func (daemon *Daemon) fillAPIInfo(v *types.Info) {
 func (daemon *Daemon) fillAPIInfo(v *types.Info) {
 	const warn string = `
 	const warn string = `
          Access to the remote API is equivalent to root access on the host. Refer
          Access to the remote API is equivalent to root access on the host. Refer