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)
| 401 | // container's processes' root filesystem in turn. Used by application-metrics |
| 402 | // collectors to read collector config files declared via container labels. |
| 403 | func (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 |