diff --git a/api/handlers.go b/api/handlers.go index e986afba16..e7468eefa4 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -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, diff --git a/cluster/cluster.go b/cluster/cluster.go index bab478055d..f1c5fd4120 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -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 diff --git a/cluster/mesos/cluster.go b/cluster/mesos/cluster.go index d2d2e50d4f..31ab34c8cc 100644 --- a/cluster/mesos/cluster.go +++ b/cluster/mesos/cluster.go @@ -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)}) } } diff --git a/cluster/swarm/cluster.go b/cluster/swarm/cluster.go index ff6507afea..86e635c6bc 100644 --- a/cluster/swarm/cluster.go +++ b/cluster/swarm/cluster.go @@ -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