commit
34eb23f004
@ -29,6 +29,7 @@ const (
|
|||||||
machineApi = "machine"
|
machineApi = "machine"
|
||||||
dockerApi = "docker"
|
dockerApi = "docker"
|
||||||
summaryApi = "summary"
|
summaryApi = "summary"
|
||||||
|
specApi = "spec"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Interface for a cAdvisor API version
|
// Interface for a cAdvisor API version
|
||||||
@ -257,6 +258,14 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
|
|||||||
}
|
}
|
||||||
|
|
||||||
return writeResult(stats, w)
|
return writeResult(stats, w)
|
||||||
|
case specApi:
|
||||||
|
containerName := getContainerName(request)
|
||||||
|
glog.V(2).Infof("Api - Spec(%v)", containerName)
|
||||||
|
spec, err := m.GetContainerSpec(containerName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return writeResult(spec, w)
|
||||||
default:
|
default:
|
||||||
return self.baseVersion.HandleRequest(requestType, request, m, w, r)
|
return self.baseVersion.HandleRequest(requestType, request, m, w, r)
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,9 @@ type Manager interface {
|
|||||||
// Gets information about a specific Docker container. The specified name is within the Docker namespace.
|
// Gets information about a specific Docker container. The specified name is within the Docker namespace.
|
||||||
DockerContainer(dockerName string, query *info.ContainerInfoRequest) (info.ContainerInfo, error)
|
DockerContainer(dockerName string, query *info.ContainerInfoRequest) (info.ContainerInfo, error)
|
||||||
|
|
||||||
|
// Gets spec for a container.
|
||||||
|
GetContainerSpec(containerName string) (info.ContainerSpec, error)
|
||||||
|
|
||||||
// Get derived stats for a container.
|
// Get derived stats for a container.
|
||||||
GetContainerDerivedStats(containerName string) (info.DerivedStats, error)
|
GetContainerDerivedStats(containerName string) (info.DerivedStats, error)
|
||||||
|
|
||||||
@ -226,8 +229,7 @@ func (self *manager) globalHousekeeping(quit chan error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a container by name.
|
func (self *manager) getContainerData(containerName string) (*containerData, error) {
|
||||||
func (self *manager) GetContainerInfo(containerName string, query *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
|
||||||
var cont *containerData
|
var cont *containerData
|
||||||
var ok bool
|
var ok bool
|
||||||
func() {
|
func() {
|
||||||
@ -242,7 +244,40 @@ func (self *manager) GetContainerInfo(containerName string, query *info.Containe
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("unknown container %q", containerName)
|
return nil, fmt.Errorf("unknown container %q", containerName)
|
||||||
}
|
}
|
||||||
|
return cont, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *manager) GetContainerSpec(containerName string) (info.ContainerSpec, error) {
|
||||||
|
cont, err := self.getContainerData(containerName)
|
||||||
|
if err != nil {
|
||||||
|
return info.ContainerSpec{}, err
|
||||||
|
}
|
||||||
|
cinfo, err := cont.GetInfo()
|
||||||
|
if err != nil {
|
||||||
|
return info.ContainerSpec{}, err
|
||||||
|
}
|
||||||
|
return self.getAdjustedSpec(cinfo), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *manager) getAdjustedSpec(cinfo *containerInfo) info.ContainerSpec {
|
||||||
|
spec := cinfo.Spec
|
||||||
|
|
||||||
|
// Set default value to an actual value
|
||||||
|
if spec.HasMemory {
|
||||||
|
// Memory.Limit is 0 means there's no limit
|
||||||
|
if spec.Memory.Limit == 0 {
|
||||||
|
spec.Memory.Limit = uint64(self.machineInfo.MemoryCapacity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a container by name.
|
||||||
|
func (self *manager) GetContainerInfo(containerName string, query *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
||||||
|
cont, err := self.getContainerData(containerName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return self.containerDataToContainerInfo(cont, query)
|
return self.containerDataToContainerInfo(cont, query)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,17 +297,9 @@ func (self *manager) containerDataToContainerInfo(cont *containerData, query *in
|
|||||||
ret := &info.ContainerInfo{
|
ret := &info.ContainerInfo{
|
||||||
ContainerReference: cinfo.ContainerReference,
|
ContainerReference: cinfo.ContainerReference,
|
||||||
Subcontainers: cinfo.Subcontainers,
|
Subcontainers: cinfo.Subcontainers,
|
||||||
Spec: cinfo.Spec,
|
Spec: self.getAdjustedSpec(cinfo),
|
||||||
Stats: stats,
|
Stats: stats,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set default value to an actual value
|
|
||||||
if ret.Spec.HasMemory {
|
|
||||||
// Memory.Limit is 0 means there's no limit
|
|
||||||
if ret.Spec.Memory.Limit == 0 {
|
|
||||||
ret.Spec.Memory.Limit = uint64(self.machineInfo.MemoryCapacity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user