type cadvisorStatsProvider … // newCadvisorStatsProvider returns a containerStatsProvider that provides // container stats from cAdvisor. func newCadvisorStatsProvider( cadvisor cadvisor.Interface, resourceAnalyzer stats.ResourceAnalyzer, imageService kubecontainer.ImageService, statusProvider status.PodStatusProvider, hostStatsProvider HostStatsProvider, ) containerStatsProvider { … } // ListPodStats returns the stats of all the pod-managed containers. func (p *cadvisorStatsProvider) ListPodStats(_ context.Context) ([]statsapi.PodStats, error) { … } // ListPodStatsAndUpdateCPUNanoCoreUsage updates the cpu nano core usage for // the containers and returns the stats for all the pod-managed containers. // For cadvisor, cpu nano core usages are pre-computed and cached, so this // function simply calls ListPodStats. func (p *cadvisorStatsProvider) ListPodStatsAndUpdateCPUNanoCoreUsage(ctx context.Context) ([]statsapi.PodStats, error) { … } // ListPodCPUAndMemoryStats returns the cpu and memory stats of all the pod-managed containers. func (p *cadvisorStatsProvider) ListPodCPUAndMemoryStats(_ context.Context) ([]statsapi.PodStats, error) { … } // ImageFsStats returns the stats of the filesystem for storing images. func (p *cadvisorStatsProvider) ImageFsStats(ctx context.Context) (imageFsRet *statsapi.FsStats, containerFsRet *statsapi.FsStats, errCall error) { … } // ImageFsDevice returns name of the device where the image filesystem locates, // e.g. /dev/sda1. func (p *cadvisorStatsProvider) ImageFsDevice(_ context.Context) (string, error) { … } // buildPodRef returns a PodReference that identifies the Pod managing cinfo func buildPodRef(containerLabels map[string]string) statsapi.PodReference { … } // isPodManagedContainer returns true if the cinfo container is managed by a Pod func isPodManagedContainer(cinfo *cadvisorapiv2.ContainerInfo) bool { … } // getCadvisorPodInfoFromPodUID returns a pod cgroup information by matching the podUID with its CgroupName identifier base name func getCadvisorPodInfoFromPodUID(podUID types.UID, infos map[string]cadvisorapiv2.ContainerInfo) *cadvisorapiv2.ContainerInfo { … } // filterTerminatedContainerInfoAndAssembleByPodCgroupKey returns the specified containerInfo but with // the stats of the terminated containers removed and all containerInfos assembled by pod cgroup key. // the first return map is container cgroup name <-> ContainerInfo and // the second return map is pod cgroup key <-> ContainerInfo. // A ContainerInfo is considered to be of a terminated container if it has an // older CreationTime and zero CPU instantaneous and memory RSS usage. func filterTerminatedContainerInfoAndAssembleByPodCgroupKey(containerInfo map[string]cadvisorapiv2.ContainerInfo) (map[string]cadvisorapiv2.ContainerInfo, map[string]cadvisorapiv2.ContainerInfo) { … } type ByCreationTime … func (a ByCreationTime) Len() int { … } func (a ByCreationTime) Swap(i, j int) { … } func (a ByCreationTime) Less(i, j int) bool { … } type containerID … type containerInfoWithCgroup … // hasMemoryAndCPUInstUsage returns true if the specified container info has // both non-zero CPU instantaneous usage and non-zero memory RSS usage, and // false otherwise. func hasMemoryAndCPUInstUsage(info *cadvisorapiv2.ContainerInfo) bool { … } // isContainerTerminated returns true if the specified container meet one of the following conditions // 1. info.spec both cpu memory and network are false conditions // 2. info.Stats both network and cpu or memory are nil // 3. both zero CPU instantaneous usage zero memory RSS usage and zero network usage, // and false otherwise. func isContainerTerminated(info *cadvisorapiv2.ContainerInfo) bool { … } func getCadvisorContainerInfo(ca cadvisor.Interface) (map[string]cadvisorapiv2.ContainerInfo, error) { … }