本文整理汇总了Golang中github.com/google/cadvisor/manager.Manager.HyperImages方法的典型用法代码示例。如果您正苦于以下问题:Golang Manager.HyperImages方法的具体用法?Golang Manager.HyperImages怎么用?Golang Manager.HyperImages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/google/cadvisor/manager.Manager
的用法示例。
在下文中一共展示了Manager.HyperImages方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: serveHyperPage
func serveHyperPage(m manager.Manager, w http.ResponseWriter, u *url.URL) error {
start := time.Now()
// The container name is the path after the handler
containerName := u.Path[len(HyperPage)-1:]
rootDir := getRootDir(containerName)
var data *pageData
if containerName == "/" {
// Get the containers.
reqParams := info.ContainerInfoRequest{
NumStats: 0,
}
conts, err := m.AllHyperContainers(&reqParams)
if err != nil {
return fmt.Errorf("failed to get container %q with error: %v", containerName, err)
}
subcontainers := make([]link, 0, len(conts))
for _, cont := range conts {
subcontainers = append(subcontainers, link{
Text: getHyperDisplayName(cont.ContainerReference),
Link: path.Join(rootDir, HyperPage, cont.ContainerReference.Name),
})
}
// Get Hyper status
status, err := m.HyperInfo()
if err != nil {
return err
}
hyperStatus, driverStatus := toStatusKV(status)
// Get Images
images, err := m.HyperImages()
if err != nil {
return err
}
hyperContainersText := "Hyper Pods"
data = &pageData{
DisplayName: hyperContainersText,
ParentContainers: []link{
{
Text: hyperContainersText,
Link: path.Join(rootDir, HyperPage),
}},
Subcontainers: subcontainers,
Root: rootDir,
DockerStatus: hyperStatus,
DockerDriverStatus: driverStatus,
DockerImages: images,
}
} else {
// Get the container.
reqParams := info.ContainerInfoRequest{
NumStats: 60,
}
cont, err := m.HyperContainer(containerName, &reqParams)
if err != nil {
return fmt.Errorf("failed to get container %q with error: %v", containerName, err)
}
displayName := getHyperDisplayName(cont.ContainerReference)
// Make a list of the parent containers and their links
var parentContainers []link
parentContainers = append(parentContainers, link{
Text: "Hyper Pods",
Link: path.Join(rootDir, HyperPage),
})
parentContainers = append(parentContainers, link{
Text: displayName,
Link: path.Join(rootDir, HyperPage, cont.Name),
})
// Get the MachineInfo
machineInfo, err := m.GetMachineInfo()
if err != nil {
return err
}
data = &pageData{
DisplayName: displayName,
ContainerName: escapeContainerName(cont.Name),
ParentContainers: parentContainers,
Spec: cont.Spec,
Stats: cont.Stats,
MachineInfo: machineInfo,
ResourcesAvailable: cont.Spec.HasCpu || cont.Spec.HasMemory || cont.Spec.HasNetwork,
CpuAvailable: cont.Spec.HasCpu,
MemoryAvailable: cont.Spec.HasMemory,
NetworkAvailable: cont.Spec.HasNetwork,
FsAvailable: cont.Spec.HasFilesystem,
CustomMetricsAvailable: cont.Spec.HasCustomMetrics,
Root: rootDir,
}
}
err := pageTemplate.Execute(w, data)
if err != nil {
glog.Errorf("Failed to apply template: %s", err)
}
//.........这里部分代码省略.........