github.com/mheon/docker@v0.11.2-0.20150922122814-44f47903a831/api/client/info.go (about)

     1  package client
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	Cli "github.com/docker/docker/cli"
     9  	"github.com/docker/docker/pkg/httputils"
    10  	"github.com/docker/docker/pkg/ioutils"
    11  	flag "github.com/docker/docker/pkg/mflag"
    12  	"github.com/docker/docker/pkg/units"
    13  )
    14  
    15  // CmdInfo displays system-wide information.
    16  //
    17  // Usage: docker info
    18  func (cli *DockerCli) CmdInfo(args ...string) error {
    19  	cmd := Cli.Subcmd("info", nil, "Display system-wide information", true)
    20  	cmd.Require(flag.Exact, 0)
    21  
    22  	cmd.ParseFlags(args, true)
    23  
    24  	serverResp, err := cli.call("GET", "/info", nil, nil)
    25  	if err != nil {
    26  		return err
    27  	}
    28  
    29  	defer serverResp.body.Close()
    30  
    31  	info := &types.Info{}
    32  	if err := json.NewDecoder(serverResp.body).Decode(info); err != nil {
    33  		return fmt.Errorf("Error reading remote info: %v", err)
    34  	}
    35  
    36  	fmt.Fprintf(cli.out, "Containers: %d\n", info.Containers)
    37  	fmt.Fprintf(cli.out, "Images: %d\n", info.Images)
    38  	fmt.Fprintf(cli.out, "Engine Version: %s\n", info.ServerVersion)
    39  	ioutils.FprintfIfNotEmpty(cli.out, "Storage Driver: %s\n", info.Driver)
    40  	if info.DriverStatus != nil {
    41  		for _, pair := range info.DriverStatus {
    42  			fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1])
    43  		}
    44  	}
    45  	ioutils.FprintfIfNotEmpty(cli.out, "Execution Driver: %s\n", info.ExecutionDriver)
    46  	ioutils.FprintfIfNotEmpty(cli.out, "Logging Driver: %s\n", info.LoggingDriver)
    47  	ioutils.FprintfIfNotEmpty(cli.out, "Kernel Version: %s\n", info.KernelVersion)
    48  	ioutils.FprintfIfNotEmpty(cli.out, "Operating System: %s\n", info.OperatingSystem)
    49  	fmt.Fprintf(cli.out, "CPUs: %d\n", info.NCPU)
    50  	fmt.Fprintf(cli.out, "Total Memory: %s\n", units.BytesSize(float64(info.MemTotal)))
    51  	ioutils.FprintfIfNotEmpty(cli.out, "Name: %s\n", info.Name)
    52  	ioutils.FprintfIfNotEmpty(cli.out, "ID: %s\n", info.ID)
    53  
    54  	if info.Debug {
    55  		fmt.Fprintf(cli.out, "Debug mode (server): %v\n", info.Debug)
    56  		fmt.Fprintf(cli.out, "File Descriptors: %d\n", info.NFd)
    57  		fmt.Fprintf(cli.out, "Goroutines: %d\n", info.NGoroutines)
    58  		fmt.Fprintf(cli.out, "System Time: %s\n", info.SystemTime)
    59  		fmt.Fprintf(cli.out, "EventsListeners: %d\n", info.NEventsListener)
    60  		fmt.Fprintf(cli.out, "Init SHA1: %s\n", info.InitSha1)
    61  		fmt.Fprintf(cli.out, "Init Path: %s\n", info.InitPath)
    62  		fmt.Fprintf(cli.out, "Docker Root Dir: %s\n", info.DockerRootDir)
    63  	}
    64  
    65  	ioutils.FprintfIfNotEmpty(cli.out, "Http Proxy: %s\n", info.HTTPProxy)
    66  	ioutils.FprintfIfNotEmpty(cli.out, "Https Proxy: %s\n", info.HTTPSProxy)
    67  	ioutils.FprintfIfNotEmpty(cli.out, "No Proxy: %s\n", info.NoProxy)
    68  
    69  	if info.IndexServerAddress != "" {
    70  		u := cli.configFile.AuthConfigs[info.IndexServerAddress].Username
    71  		if len(u) > 0 {
    72  			fmt.Fprintf(cli.out, "Username: %v\n", u)
    73  			fmt.Fprintf(cli.out, "Registry: %v\n", info.IndexServerAddress)
    74  		}
    75  	}
    76  	// Only output these warnings if the server supports these features
    77  	if h, err := httputils.ParseServerHeader(serverResp.header.Get("Server")); err == nil {
    78  		if h.OS != "windows" {
    79  			if !info.MemoryLimit {
    80  				fmt.Fprintf(cli.err, "WARNING: No memory limit support\n")
    81  			}
    82  			if !info.SwapLimit {
    83  				fmt.Fprintf(cli.err, "WARNING: No swap limit support\n")
    84  			}
    85  			if !info.IPv4Forwarding {
    86  				fmt.Fprintf(cli.err, "WARNING: IPv4 forwarding is disabled\n")
    87  			}
    88  			if !info.BridgeNfIptables {
    89  				fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-iptables is disabled\n")
    90  			}
    91  			if !info.BridgeNfIP6tables {
    92  				fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-ip6tables is disabled\n")
    93  			}
    94  		}
    95  	}
    96  
    97  	if info.Labels != nil {
    98  		fmt.Fprintln(cli.out, "Labels:")
    99  		for _, attribute := range info.Labels {
   100  			fmt.Fprintf(cli.out, " %s\n", attribute)
   101  		}
   102  	}
   103  
   104  	if info.ExperimentalBuild {
   105  		fmt.Fprintf(cli.out, "Experimental: true\n")
   106  	}
   107  
   108  	return nil
   109  }