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

Method ReadFile

lib/manager/container.go:403–419  ·  view source on GitHub ↗

ReadFile reads a file from inside the container, trying each of the container's processes' root filesystem in turn. Used by application-metrics collectors to read collector config files declared via container labels.

(filepath string, inHostNamespace bool)

Source from the content-addressed store, hash-verified

401// container's processes' root filesystem in turn. Used by application-metrics
402// collectors to read collector config files declared via container labels.
403func (cd *containerData) ReadFile(filepath string, inHostNamespace bool) ([]byte, error) {
404 pids, err := cd.handler.ListProcesses(container.ListSelf)
405 if err != nil {
406 return nil, err
407 }
408 rootfs := "/"
409 if !inHostNamespace {
410 rootfs = "/rootfs"
411 }
412 for _, pid := range pids {
413 fp := path.Join(rootfs, "/proc", strconv.Itoa(pid), "/root", filepath)
414 if data, rerr := os.ReadFile(fp); rerr == nil {
415 return data, nil
416 }
417 }
418 return nil, fmt.Errorf("file %q does not exist", filepath)
419}
420
421// Calculate new smoothed load average using the new sample of runnable threads.
422// The decay used ensures that the load will stabilize on a new constant value within

Callers 15

getRwLayerIDFunction · 0.80
rwLayerIDFunction · 0.80
PushAndRunTestsFunction · 0.80
IsActiveProviderMethod · 0.80
GetInstanceIDMethod · 0.80
IsActiveProviderMethod · 0.80
getFileContentFunction · 0.80
processRootProcUlimitsFunction · 0.80
processStatsFromProcsFunction · 0.80
scanAdvancedTCPStatsFunction · 0.80
scanTCPStatsFunction · 0.80

Calls 2

ErrorfMethod · 0.80
ListProcessesMethod · 0.65