mirror of https://github.com/docker/docs.git
Merge pull request #902 from vieux/improve_docker_info
Improve docker info against 1.7
This commit is contained in:
commit
47dbb5a30d
|
@ -24,18 +24,17 @@ const APIVERSION = "1.16"
|
|||
|
||||
// GET /info
|
||||
func getInfo(c *context, w http.ResponseWriter, r *http.Request) {
|
||||
info := struct {
|
||||
Containers int
|
||||
Images int
|
||||
DriverStatus [][2]string
|
||||
NEventsListener int
|
||||
Debug bool
|
||||
}{
|
||||
len(c.cluster.Containers()),
|
||||
len(c.cluster.Images()),
|
||||
c.cluster.Info(),
|
||||
c.eventsHandler.Size(),
|
||||
c.debug,
|
||||
info := dockerclient.Info{
|
||||
Containers: int64(len(c.cluster.Containers())),
|
||||
Images: int64(len(c.cluster.Images())),
|
||||
DriverStatus: c.cluster.Info(),
|
||||
NEventsListener: int64(c.eventsHandler.Size()),
|
||||
Debug: c.debug,
|
||||
MemoryLimit: true,
|
||||
SwapLimit: true,
|
||||
IPv4Forwarding: true,
|
||||
NCPU: c.cluster.TotalCpus(),
|
||||
MemTotal: c.cluster.TotalMemory(),
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
@ -44,16 +43,9 @@ func getInfo(c *context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// GET /version
|
||||
func getVersion(c *context, w http.ResponseWriter, r *http.Request) {
|
||||
version := struct {
|
||||
Version string
|
||||
APIVersion string `json:"ApiVersion"`
|
||||
GoVersion string
|
||||
GitCommit string
|
||||
Os string
|
||||
Arch string
|
||||
}{
|
||||
version := dockerclient.Version{
|
||||
Version: "swarm/" + version.VERSION,
|
||||
APIVersion: APIVERSION,
|
||||
ApiVersion: APIVERSION,
|
||||
GoVersion: runtime.Version(),
|
||||
GitCommit: version.GITCOMMIT,
|
||||
Os: runtime.GOOS,
|
||||
|
|
|
@ -51,7 +51,13 @@ type Cluster interface {
|
|||
|
||||
// Return some info about the cluster, like nb or containers / images
|
||||
// It is pretty open, so the implementation decides what to return.
|
||||
Info() [][2]string
|
||||
Info() [][]string
|
||||
|
||||
// Return the total memory of the cluster
|
||||
TotalMemory() int64
|
||||
|
||||
// Return the number of CPUs in the cluster
|
||||
TotalCpus() int64
|
||||
|
||||
// Register an event handler for cluster-wide events.
|
||||
RegisterEventHandler(h EventHandler) error
|
||||
|
|
|
@ -302,10 +302,22 @@ func (c *Cluster) listOffers() []*mesosproto.Offer {
|
|||
return list
|
||||
}
|
||||
|
||||
// TotalMemory return the total memory of the cluster
|
||||
func (c *Cluster) TotalMemory() int64 {
|
||||
// TODO: use current offers
|
||||
return 0
|
||||
}
|
||||
|
||||
// TotalCpus return the total memory of the cluster
|
||||
func (c *Cluster) TotalCpus() int64 {
|
||||
// TODO: use current offers
|
||||
return 0
|
||||
}
|
||||
|
||||
// Info gives minimal information about containers and resources on the mesos cluster
|
||||
func (c *Cluster) Info() [][2]string {
|
||||
func (c *Cluster) Info() [][]string {
|
||||
offers := c.listOffers()
|
||||
info := [][2]string{
|
||||
info := [][]string{
|
||||
{"\bStrategy", c.scheduler.Strategy()},
|
||||
{"\bFilters", c.scheduler.Filters()},
|
||||
{"\bOffers", fmt.Sprintf("%d", len(offers))},
|
||||
|
@ -314,9 +326,9 @@ func (c *Cluster) Info() [][2]string {
|
|||
sort.Sort(offerSorter(offers))
|
||||
|
||||
for _, offer := range offers {
|
||||
info = append(info, [2]string{" Offer", offer.Id.GetValue()})
|
||||
info = append(info, []string{" Offer", offer.Id.GetValue()})
|
||||
for _, resource := range offer.Resources {
|
||||
info = append(info, [2]string{" └ " + *resource.Name, fmt.Sprintf("%v", resource)})
|
||||
info = append(info, []string{" └ " + *resource.Name, fmt.Sprintf("%v", resource)})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -497,9 +497,27 @@ func (c *Cluster) listEngines() []*cluster.Engine {
|
|||
return out
|
||||
}
|
||||
|
||||
// Info is exported
|
||||
func (c *Cluster) Info() [][2]string {
|
||||
info := [][2]string{
|
||||
// TotalMemory return the total memory of the cluster
|
||||
func (c *Cluster) TotalMemory() int64 {
|
||||
var totalMemory int64
|
||||
for _, engine := range c.engines {
|
||||
totalMemory += engine.TotalMemory()
|
||||
}
|
||||
return totalMemory
|
||||
}
|
||||
|
||||
// TotalCpus return the total memory of the cluster
|
||||
func (c *Cluster) TotalCpus() int64 {
|
||||
var totalCpus int64
|
||||
for _, engine := range c.engines {
|
||||
totalCpus += engine.TotalCpus()
|
||||
}
|
||||
return totalCpus
|
||||
}
|
||||
|
||||
// Info returns some info about the cluster, like nb or containers / images
|
||||
func (c *Cluster) Info() [][]string {
|
||||
info := [][]string{
|
||||
{"\bStrategy", c.scheduler.Strategy()},
|
||||
{"\bFilters", c.scheduler.Filters()},
|
||||
{"\bNodes", fmt.Sprintf("%d", len(c.engines))},
|
||||
|
@ -509,16 +527,16 @@ func (c *Cluster) Info() [][2]string {
|
|||
sort.Sort(cluster.EngineSorter(engines))
|
||||
|
||||
for _, engine := range engines {
|
||||
info = append(info, [2]string{engine.Name, engine.Addr})
|
||||
info = append(info, [2]string{" └ Containers", fmt.Sprintf("%d", len(engine.Containers()))})
|
||||
info = append(info, [2]string{" └ Reserved CPUs", fmt.Sprintf("%d / %d", engine.UsedCpus(), engine.TotalCpus())})
|
||||
info = append(info, [2]string{" └ Reserved Memory", fmt.Sprintf("%s / %s", units.BytesSize(float64(engine.UsedMemory())), units.BytesSize(float64(engine.TotalMemory())))})
|
||||
info = append(info, []string{engine.Name, engine.Addr})
|
||||
info = append(info, []string{" └ Containers", fmt.Sprintf("%d", len(engine.Containers()))})
|
||||
info = append(info, []string{" └ Reserved CPUs", fmt.Sprintf("%d / %d", engine.UsedCpus(), engine.TotalCpus())})
|
||||
info = append(info, []string{" └ Reserved Memory", fmt.Sprintf("%s / %s", units.BytesSize(float64(engine.UsedMemory())), units.BytesSize(float64(engine.TotalMemory())))})
|
||||
labels := make([]string, 0, len(engine.Labels))
|
||||
for k, v := range engine.Labels {
|
||||
labels = append(labels, k+"="+v)
|
||||
}
|
||||
sort.Strings(labels)
|
||||
info = append(info, [2]string{" └ Labels", fmt.Sprintf("%s", strings.Join(labels, ", "))})
|
||||
info = append(info, []string{" └ Labels", fmt.Sprintf("%s", strings.Join(labels, ", "))})
|
||||
}
|
||||
|
||||
return info
|
||||
|
|
Loading…
Reference in New Issue