MCPcopy
hub / github.com/google/cadvisor / updateStats

Method updateStats

lib/manager/container.go:440–521  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

438}
439
440func (cd *containerData) updateStats() error {
441 stats, statsErr := cd.handler.GetStats()
442 if statsErr != nil {
443 // Ignore errors if the container is dead.
444 if !cd.handler.Exists() {
445 return nil
446 }
447
448 // Stats may be partially populated, push those before we return an error.
449 statsErr = fmt.Errorf("%v, continuing to push stats", statsErr)
450 }
451 if stats == nil {
452 return statsErr
453 }
454 if cd.loadReader != nil {
455 // TODO(vmarmol): Cache this path.
456 path, err := cd.handler.GetCgroupPath("cpu")
457 if err == nil {
458 loadStats, err := cd.loadReader.GetCpuLoad(cd.info.Name, path)
459 if err != nil {
460 return fmt.Errorf("failed to get load stat for %q - path %q, error %s", cd.info.Name, path, err)
461 }
462 stats.TaskStats = loadStats
463 cd.updateLoad(loadStats.NrRunning)
464 // convert to 'milliLoad' to avoid floats and preserve precision.
465 stats.Cpu.LoadAverage = int32(cd.loadAvg * 1000)
466
467 cd.updateLoadD(loadStats.NrUninterruptible)
468 // convert to 'milliLoad' to avoid floats and preserve precision.
469 stats.Cpu.LoadDAverage = int32(cd.loadDAvg * 1000)
470 }
471 }
472
473 if cd.summaryReader != nil {
474 if err := cd.summaryReader.AddSample(*stats); err != nil {
475 // Ignore summary errors for now.
476 klog.V(2).Infof("Failed to add summary stats for %q: %v", cd.info.Name, err)
477 }
478 }
479
480 if cd.collectorManager != nil {
481 if _, custom, cerr := cd.collectorManager.Collect(); cerr != nil {
482 klog.V(2).Infof("Failed to collect custom stats for %q: %v", cd.info.Name, cerr)
483 } else if len(custom) > 0 {
484 stats.CustomMetrics = custom
485 }
486 }
487
488 perfStatsErr := cd.perfCollector.UpdateStats(stats)
489
490 resctrlStatsErr := cd.resctrlCollector.UpdateStats(stats)
491
492 ref, err := cd.handler.ContainerReference()
493 if err != nil {
494 // Ignore errors if the container is dead.
495 if !cd.handler.Exists() {
496 return nil
497 }

Callers 2

housekeepingTickMethod · 0.95
TestUpdateStatsFunction · 0.80

Calls 13

updateLoadMethod · 0.95
updateLoadDMethod · 0.95
ErrorfMethod · 0.80
InfofMethod · 0.80
GetStatsMethod · 0.65
ExistsMethod · 0.65
GetCgroupPathMethod · 0.65
GetCpuLoadMethod · 0.65
AddSampleMethod · 0.65
CollectMethod · 0.65
UpdateStatsMethod · 0.65
ContainerReferenceMethod · 0.65

Tested by 1

TestUpdateStatsFunction · 0.64