changed pages and manager.
This commit is contained in:
parent
89b5484734
commit
163179a84e
@ -63,8 +63,10 @@ func (self *percentilesContainerHandlerWrapper) GetStats() (*info.ContainerStats
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// nil stats and nil error is possible for /docker container.
|
||||||
if stats == nil {
|
if stats == nil {
|
||||||
return nil, fmt.Errorf("container handler returns a nil error and a nil stats")
|
// return nil, fmt.Errorf("container handler returns a nil error and a nil stats")
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
if stats.Timestamp.IsZero() {
|
if stats.Timestamp.IsZero() {
|
||||||
return nil, fmt.Errorf("container handler did not set timestamp")
|
return nil, fmt.Errorf("container handler did not set timestamp")
|
||||||
|
@ -35,8 +35,8 @@ type containerStat struct {
|
|||||||
Data *info.ContainerStats
|
Data *info.ContainerStats
|
||||||
}
|
}
|
||||||
type containerInfo struct {
|
type containerInfo struct {
|
||||||
Name string
|
info.ContainerRef
|
||||||
Subcontainers []string
|
Subcontainers []info.ContainerRef
|
||||||
Spec *info.ContainerSpec
|
Spec *info.ContainerSpec
|
||||||
Stats *list.List
|
Stats *list.List
|
||||||
StatsSummary *info.ContainerStatsPercentiles
|
StatsSummary *info.ContainerStatsPercentiles
|
||||||
|
@ -111,7 +111,9 @@ func (m *manager) GetContainerInfo(containerName string) (*info.ContainerInfo, e
|
|||||||
|
|
||||||
// Make a copy of the info for the user.
|
// Make a copy of the info for the user.
|
||||||
ret := &info.ContainerInfo{
|
ret := &info.ContainerInfo{
|
||||||
Name: cinfo.Name,
|
ContainerRef: info.ContainerRef{
|
||||||
|
Name: cinfo.Name,
|
||||||
|
},
|
||||||
Subcontainers: cinfo.Subcontainers,
|
Subcontainers: cinfo.Subcontainers,
|
||||||
Spec: cinfo.Spec,
|
Spec: cinfo.Spec,
|
||||||
StatsSummary: cinfo.StatsSummary,
|
StatsSummary: cinfo.StatsSummary,
|
||||||
@ -180,10 +182,8 @@ func (m *manager) destroyContainer(containerName string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type empty struct{}
|
|
||||||
|
|
||||||
// Detect all containers that have been added or deleted.
|
// Detect all containers that have been added or deleted.
|
||||||
func (m *manager) getContainersDiff() (added []string, removed []string, err error) {
|
func (m *manager) getContainersDiff() (added []info.ContainerRef, removed []info.ContainerRef, err error) {
|
||||||
// TODO(vmarmol): We probably don't need to lock around / since it will always be there.
|
// TODO(vmarmol): We probably don't need to lock around / since it will always be there.
|
||||||
m.containersLock.RLock()
|
m.containersLock.RLock()
|
||||||
defer m.containersLock.RUnlock()
|
defer m.containersLock.RUnlock()
|
||||||
@ -197,24 +197,24 @@ func (m *manager) getContainersDiff() (added []string, removed []string, err err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
allContainers = append(allContainers, "/")
|
allContainers = append(allContainers, info.ContainerRef{Name: "/"})
|
||||||
|
|
||||||
// Determine which were added and which were removed.
|
// Determine which were added and which were removed.
|
||||||
allContainersSet := make(map[string]*empty)
|
allContainersSet := make(map[string]*containerData)
|
||||||
for name, _ := range m.containers {
|
for name, d := range m.containers {
|
||||||
allContainersSet[name] = &empty{}
|
allContainersSet[name] = d
|
||||||
}
|
}
|
||||||
for _, name := range allContainers {
|
for _, c := range allContainers {
|
||||||
delete(allContainersSet, name)
|
delete(allContainersSet, c.Name)
|
||||||
_, ok := m.containers[name]
|
_, ok := m.containers[c.Name]
|
||||||
if !ok {
|
if !ok {
|
||||||
added = append(added, name)
|
added = append(added, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removed ones are no longer in the container listing.
|
// Removed ones are no longer in the container listing.
|
||||||
for name, _ := range allContainersSet {
|
for _, d := range allContainersSet {
|
||||||
removed = append(removed, name)
|
removed = append(removed, d.info.ContainerRef)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -228,18 +228,18 @@ func (m *manager) detectContainers() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the new containers.
|
// Add the new containers.
|
||||||
for _, name := range added {
|
for _, c := range added {
|
||||||
_, err = m.createContainer(name)
|
_, err = m.createContainer(c.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to create existing container: %s: %s", name, err)
|
return fmt.Errorf("Failed to create existing container: %s: %s", c.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the old containers.
|
// Remove the old containers.
|
||||||
for _, name := range removed {
|
for _, c := range removed {
|
||||||
err = m.destroyContainer(name)
|
err = m.destroyContainer(c.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to destroy existing container: %s: %s", name, err)
|
return fmt.Errorf("Failed to destroy existing container: %s: %s", c.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +50,8 @@ var pageTemplate *template.Template
|
|||||||
|
|
||||||
type pageData struct {
|
type pageData struct {
|
||||||
ContainerName string
|
ContainerName string
|
||||||
ParentContainers []string
|
ParentContainers []info.ContainerRef
|
||||||
Subcontainers []string
|
Subcontainers []info.ContainerRef
|
||||||
Spec *info.ContainerSpec
|
Spec *info.ContainerSpec
|
||||||
Stats []*info.ContainerStats
|
Stats []*info.ContainerStats
|
||||||
MachineInfo *info.MachineInfo
|
MachineInfo *info.MachineInfo
|
||||||
@ -69,14 +69,17 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO(vmarmol): Escape this correctly.
|
// TODO(vmarmol): Escape this correctly.
|
||||||
func containerLink(containerName string, basenameOnly bool, cssClasses string) interface{} {
|
func containerLink(containerRef info.ContainerRef, basenameOnly bool, cssClasses string) interface{} {
|
||||||
var displayName string
|
var displayName string
|
||||||
if basenameOnly {
|
containerName := containerRef.Name
|
||||||
displayName = path.Base(string(containerName))
|
if len(containerRef.Aliases) > 0 {
|
||||||
|
displayName = containerRef.Aliases[0]
|
||||||
|
} else if basenameOnly {
|
||||||
|
displayName = path.Base(string(containerRef.Name))
|
||||||
} else {
|
} else {
|
||||||
displayName = string(containerName)
|
displayName = string(containerRef.Name)
|
||||||
}
|
}
|
||||||
if containerName == "root" {
|
if containerRef.Name == "root" {
|
||||||
containerName = "/"
|
containerName = "/"
|
||||||
}
|
}
|
||||||
return template.HTML(fmt.Sprintf("<a class=\"%s\" href=\"%s%s\">%s</a>", cssClasses, ContainersPage[:len(ContainersPage)-1], containerName, displayName))
|
return template.HTML(fmt.Sprintf("<a class=\"%s\" href=\"%s%s\">%s</a>", cssClasses, ContainersPage[:len(ContainersPage)-1], containerName, displayName))
|
||||||
@ -167,15 +170,15 @@ func ServerContainersPage(m manager.Manager, w http.ResponseWriter, u *url.URL)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make a list of the parent containers and their links
|
// Make a list of the parent containers and their links
|
||||||
var parentContainers []string
|
var parentContainers []info.ContainerRef
|
||||||
parentContainers = append(parentContainers, string("root"))
|
parentContainers = append(parentContainers, info.ContainerRef{Name: "root"})
|
||||||
parentName := ""
|
parentName := ""
|
||||||
for _, part := range strings.Split(string(cont.Name), "/") {
|
for _, part := range strings.Split(string(cont.Name), "/") {
|
||||||
if part == "" {
|
if part == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
parentName += "/" + part
|
parentName += "/" + part
|
||||||
parentContainers = append(parentContainers, string(parentName))
|
parentContainers = append(parentContainers, info.ContainerRef{Name: parentName})
|
||||||
}
|
}
|
||||||
|
|
||||||
data := &pageData{
|
data := &pageData{
|
||||||
|
Loading…
Reference in New Issue
Block a user