Skip to content

Commit

Permalink
fix crash when memory metric can't be collected
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiyuechen committed Dec 13, 2022
1 parent a4088c7 commit 403a15a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/ensurance/collector/cadvisor/cadvisor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ func (c *CadvisorCollector) Collect() (map[string][]common.TimeSeries, error) {

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))
if v.Stats[0].Memory != nil {
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))
}

if state, ok := c.latestContainersStates[key]; ok {
klog.V(6).Infof("For key %s, LatestContainersStates exist", key)
Expand Down

0 comments on commit 403a15a

Please sign in to comment.