1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Show devicemapper status in "docker info"

This shows the current global diskspace use in "docker info"
This commit is contained in:
Alexander Larsson 2013-10-17 11:16:50 +02:00
parent ad2fbd9e87
commit d733cdcebb
4 changed files with 88 additions and 24 deletions

View file

@ -19,18 +19,23 @@ type APIImages struct {
} }
type APIInfo struct { type APIInfo struct {
Debug bool Debug bool
Containers int Containers int
Images int Images int
NFd int `json:",omitempty"` NFd int `json:",omitempty"`
NGoroutines int `json:",omitempty"` NGoroutines int `json:",omitempty"`
MemoryLimit bool `json:",omitempty"` MemoryLimit bool `json:",omitempty"`
SwapLimit bool `json:",omitempty"` SwapLimit bool `json:",omitempty"`
IPv4Forwarding bool `json:",omitempty"` IPv4Forwarding bool `json:",omitempty"`
LXCVersion string `json:",omitempty"` LXCVersion string `json:",omitempty"`
NEventsListener int `json:",omitempty"` NEventsListener int `json:",omitempty"`
KernelVersion string `json:",omitempty"` KernelVersion string `json:",omitempty"`
IndexServerAddress string `json:",omitempty"` IndexServerAddress string `json:",omitempty"`
DevmapperPool string `json:",omitempty"`
DevmapperDataUsed uint64 `json:",omitempty"`
DevmapperDataTotal uint64 `json:",omitempty"`
DevmapperMetadataUsed uint64 `json:",omitempty"`
DevmapperMetadataTotal uint64 `json:",omitempty"`
} }
type APITop struct { type APITop struct {

View file

@ -465,6 +465,11 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
fmt.Fprintf(cli.out, "Containers: %d\n", out.Containers) fmt.Fprintf(cli.out, "Containers: %d\n", out.Containers)
fmt.Fprintf(cli.out, "Images: %d\n", out.Images) fmt.Fprintf(cli.out, "Images: %d\n", out.Images)
if out.DevmapperDataTotal != 0 {
fmt.Fprintf(cli.out, "Devmapper disk use: Data: %.1f/%.1f Metadata: %.1f/%.1f\n",
float64(out.DevmapperDataUsed)/(1024*1024), float64(out.DevmapperDataTotal)/(1024*1024),
float64(out.DevmapperMetadataUsed)/(1024*1024), float64(out.DevmapperMetadataTotal)/(1024*1024))
}
if out.Debug || os.Getenv("DEBUG") != "" { if out.Debug || os.Getenv("DEBUG") != "" {
fmt.Fprintf(cli.out, "Debug mode (server): %v\n", out.Debug) fmt.Fprintf(cli.out, "Debug mode (server): %v\n", out.Debug)
fmt.Fprintf(cli.out, "Debug mode (client): %v\n", os.Getenv("DEBUG") != "") fmt.Fprintf(cli.out, "Debug mode (client): %v\n", os.Getenv("DEBUG") != "")
@ -473,6 +478,7 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
fmt.Fprintf(cli.out, "LXC Version: %s\n", out.LXCVersion) fmt.Fprintf(cli.out, "LXC Version: %s\n", out.LXCVersion)
fmt.Fprintf(cli.out, "EventsListeners: %d\n", out.NEventsListener) fmt.Fprintf(cli.out, "EventsListeners: %d\n", out.NEventsListener)
fmt.Fprintf(cli.out, "Kernel Version: %s\n", out.KernelVersion) fmt.Fprintf(cli.out, "Kernel Version: %s\n", out.KernelVersion)
fmt.Fprintf(cli.out, "Devmapper pool: %s\n", out.DevmapperPool)
} }
if len(out.IndexServerAddress) != 0 { if len(out.IndexServerAddress) != 0 {

View file

@ -47,6 +47,19 @@ type DeviceSetDM struct {
activeMounts map[string]int activeMounts map[string]int
} }
type DiskUsage struct {
Used uint64
Total uint64
}
type Status struct {
PoolName string
DataLoopback string
MetadataLoopback string
Data DiskUsage
Metadata DiskUsage
}
func getDevName(name string) string { func getDevName(name string) string {
return "/dev/mapper/" + name return "/dev/mapper/" + name
} }
@ -774,6 +787,39 @@ func (devices *DeviceSetDM) SetInitialized(hash string) error {
return nil return nil
} }
func (devices *DeviceSetDM) Status() *Status {
devices.Lock()
defer devices.Unlock()
status := &Status {}
if err := devices.ensureInit(); err != nil {
return status
}
status.PoolName = devices.getPoolName()
status.DataLoopback = path.Join( devices.loopbackDir(), "data")
status.MetadataLoopback = path.Join( devices.loopbackDir(), "metadata")
_, totalSizeInSectors, _, params, err := getStatus(devices.getPoolName())
if err == nil {
var transactionId, dataUsed, dataTotal, metadataUsed, metadataTotal uint64
if _, err := fmt.Sscanf(params, "%d %d/%d %d/%d", &transactionId, &metadataUsed, &metadataTotal, &dataUsed, &dataTotal); err == nil {
// Convert from blocks to bytes
blockSizeInSectors := totalSizeInSectors / dataTotal;
status.Data.Used = dataUsed * blockSizeInSectors * 512
status.Data.Total = dataTotal * blockSizeInSectors * 512
// metadata blocks are always 4k
status.Metadata.Used = metadataUsed * 4096
status.Metadata.Total = metadataTotal * 4096
}
}
return status
}
func (devices *DeviceSetDM) ensureInit() error { func (devices *DeviceSetDM) ensureInit() error {
if !devices.initialized { if !devices.initialized {
devices.initialized = true devices.initialized = true

View file

@ -268,19 +268,26 @@ func (srv *Server) DockerInfo() *APIInfo {
kernelVersion = kv.String() kernelVersion = kv.String()
} }
devSetInfo := srv.runtime.deviceSet.Status()
return &APIInfo{ return &APIInfo{
Containers: len(srv.runtime.List()), Containers: len(srv.runtime.List()),
Images: imgcount, Images: imgcount,
MemoryLimit: srv.runtime.capabilities.MemoryLimit, MemoryLimit: srv.runtime.capabilities.MemoryLimit,
SwapLimit: srv.runtime.capabilities.SwapLimit, SwapLimit: srv.runtime.capabilities.SwapLimit,
IPv4Forwarding: !srv.runtime.capabilities.IPv4ForwardingDisabled, IPv4Forwarding: !srv.runtime.capabilities.IPv4ForwardingDisabled,
Debug: os.Getenv("DEBUG") != "", Debug: os.Getenv("DEBUG") != "",
NFd: utils.GetTotalUsedFds(), NFd: utils.GetTotalUsedFds(),
NGoroutines: runtime.NumGoroutine(), NGoroutines: runtime.NumGoroutine(),
LXCVersion: lxcVersion, LXCVersion: lxcVersion,
NEventsListener: len(srv.events), NEventsListener: len(srv.events),
KernelVersion: kernelVersion, KernelVersion: kernelVersion,
IndexServerAddress: auth.IndexServerAddress(), IndexServerAddress: auth.IndexServerAddress(),
DevmapperPool: devSetInfo.PoolName,
DevmapperDataUsed: devSetInfo.Data.Used,
DevmapperDataTotal: devSetInfo.Data.Total,
DevmapperMetadataUsed: devSetInfo.Metadata.Used,
DevmapperMetadataTotal: devSetInfo.Metadata.Total,
} }
} }