Reading a container's /proc/loadavg, but on the host itself

System information
Ubuntu 22.04.3
Linux kernel 6.4.6
LXC 5.0.0 (from Ubuntu’s universe repo)
LXCFS service configured with --enable-loadavg, and working perfectly


Question

I would like to read a container’s /proc/loadavg, but without needing to enter on it to do so.

Is there is any file on the host where I could read this specific virtualized mountpoint without entering in the container itself? Or an lxc command?

I already did a research on many directories, including /sys/fs/cgroup/, /var/lib/lxc, /var/lib/lxcfs, to no avail.


The current challenges:

  • lxc-top only provides the current CPU usage, not the three averages (of 1 minute, 5 and 15), like /proc/loadavg
  • entering the container to read the file can be susceptible to slowdowns if the container is performing heavy tasks

The solution is to read the “live” filesystem from the container through /proc/<container-pid>/root/

For example, to read /proc/loadavg from a container named test-container:

1. Get the container current PID

$ lxc-info -n test-container

Name:           test-container
State:          RUNNING
PID:            10835
IP:             10.0.3.64
Link:           vethOoD3AW
 TX bytes:      1.89 KiB
 RX bytes:      2.14 KiB
 Total bytes:   4.03 KiB

2. Read the relative path, starting with the prefix /proc/<container-pid>/root/:

$ cat /proc/10835/root/proc/loadavg

0.00 0.00 0.00 0/1 11202