Skip to content

Commit

Permalink
Merge pull request #650 from chenkaiyue/memory-metric-lose-crash
Browse files Browse the repository at this point in the history
Fix crash when memory metric can't be collected
  • Loading branch information
qmhu authored Dec 15, 2022
2 parents 2fcdce0 + 403a15a commit b8415e8
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 b8415e8

Please sign in to comment.