diff --git a/pkg/ensurance/collector/cadvisor/cadvisor_linux.go b/pkg/ensurance/collector/cadvisor/cadvisor_linux.go index 5be6ab41b..aabcfe48a 100644 --- a/pkg/ensurance/collector/cadvisor/cadvisor_linux.go +++ b/pkg/ensurance/collector/cadvisor/cadvisor_linux.go @@ -162,7 +162,8 @@ func (c *CadvisorCollector) Collect() (map[string][]common.TimeSeries, error) { extResMemUse += float64(v.Stats[0].Memory.WorkingSet) } - var containerLabels = GetContainerLabels(pod, containerId, containerName, hasExtCpuRes) + hasExtRes := hasExtCpuRes || hasExtMemRes + var containerLabels = GetContainerLabels(pod, containerId, containerName, hasExtRes) addSampleToStateMap(types.MetricNameContainerMemTotalUsage, composeSample(containerLabels, float64(v.Stats[0].Memory.WorkingSet), now), stateMap) klog.V(6).Infof("Pod: %s, containerName: %s, key %s, container_mem_total_usage %#v", klog.KObj(pod), containerName, key, float64(v.Stats[0].Memory.WorkingSet)) diff --git a/pkg/utils/pod.go b/pkg/utils/pod.go index 047c37494..bcccdf7d4 100644 --- a/pkg/utils/pod.go +++ b/pkg/utils/pod.go @@ -205,8 +205,8 @@ func GetContainerNameFromPod(pod *v1.Pod, containerId string) string { if len(strList) > 0 { klog.V(6).Infof("cri-containerd is %s ", "cri-containerd-"+strList[len(strList)-1]+".scope") klog.V(6).Infof("containerid is %s", containerId) - if "cri-containerd-"+strList[len(strList)-1]+".scope" == containerId { - klog.V(6).Infof("111111111") + containerIdFromPod := fmt.Sprintf("cri-containerd-%s.scope", strList[len(strList)-1]) + if containerIdFromPod == containerId { return v.Name } }