Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
Victor Vieux 2015-06-04 18:25:32 -07:00
parent 4f9c9f5867
commit c1020da636
4 changed files with 46 additions and 13 deletions

View File

@ -24,18 +24,17 @@ const APIVERSION = "1.16"
// GET /info
func getInfo(c *context, w http.ResponseWriter, r *http.Request) {
clusterInfo, totalMemory, totalCpus := c.cluster.Info()
info := dockerclient.Info{
Containers: int64(len(c.cluster.Containers())),
Images: int64(len(c.cluster.Images())),
DriverStatus: clusterInfo,
DriverStatus: c.cluster.Info(),
NEventsListener: int64(c.eventsHandler.Size()),
Debug: c.debug,
MemoryLimit: true,
SwapLimit: true,
IPv4Forwarding: true,
NCPU: totalCpus,
MemTotal: totalMemory,
NCPU: c.cluster.TotalCpus(),
MemTotal: c.cluster.TotalMemory(),
}
w.Header().Set("Content-Type", "application/json")

View File

@ -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() ([][]string, int64, int64)
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

View File

@ -302,8 +302,20 @@ 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() ([][]string, int64, int64) {
func (c *Cluster) Info() [][]string {
offers := c.listOffers()
info := [][]string{
{"\bStrategy", c.scheduler.Strategy()},
@ -320,7 +332,7 @@ func (c *Cluster) Info() ([][]string, int64, int64) {
}
}
return info, 0, 0
return info
}
func (c *Cluster) addOffer(offer *mesosproto.Offer) {

View File

@ -497,9 +497,27 @@ func (c *Cluster) listEngines() []*cluster.Engine {
return out
}
// Info is exported
func (c *Cluster) Info() (info [][]string, totalMemory int64, totalCpus int64) {
info = [][]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))},
@ -519,11 +537,9 @@ func (c *Cluster) Info() (info [][]string, totalMemory int64, totalCpus int64) {
}
sort.Strings(labels)
info = append(info, []string{" └ Labels", fmt.Sprintf("%s", strings.Join(labels, ", "))})
totalMemory += engine.TotalMemory()
totalCpus += engine.TotalCpus()
}
return info, totalMemory, totalCpus
return info
}
// RANDOMENGINE returns a random engine.