当前位置: 首页>>代码示例>>Golang>>正文


Golang Manager.HyperImages方法代码示例

本文整理汇总了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)
	}
//.........这里部分代码省略.........
开发者ID:hyperhq,项目名称:cadvisor,代码行数:101,代码来源:hyper.go


注:本文中的github.com/google/cadvisor/manager.Manager.HyperImages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。