How can I tell how much memory an lxc container is using?


(Akshat Jiwan Sharma) #1

Using htop or free inside a container gives the information for host machine resources. However I want the utilization status specific to the container. lxc info on a container id gives me the following result:-

Resources:
  Processes: 153
  Memory usage:
    Memory (current): 1.44GB
    Memory (peak): 1.52GB
  Network usage:
    eth0:
      Bytes received: 1.39MB
      Bytes sent: 7.71MB
      Packets received: 6967
      Packets sent: 7041
    lo:
      Bytes received: 1.73MB
      Bytes sent: 1.73MB
      Packets received: 3989
      Packets sent: 3989
    lxdbr0:
      Bytes received: 0B
      Bytes sent: 470B
      Packets received: 0
      Packets sent: 5

But this information is not consistent with htop on the host machine. htop tells me that each container is using 98M of memory. Even if I account for slight difference in measurement 98 MB and 1.44GB are two very different results. What is the best way to find the memory usage of a container?

Thanks,
Akshat


(St├ęphane Graber) #2

htop is unlikely to get the whole picture when it comes to container memory consumption. You need to look at all the processes that are running inside the container AND also account for any tmpfs filesystems or similar kernel resource usage.

You probably should consider installing "lxcfs" on your system which would then have "free" and other commands report the right values inside the container.


(Akshat Jiwan Sharma) #3

Thank you @stgraber I already have lxcfs installed. Do I need to do anything else to make it work? I did take a look at the reference but I'm not sure how to use it...

Is the output of lxc info (like the one I posted in the description above) reliable? Can I accept the memory stats it gives me back?


(St├ęphane Graber) #4

Odd, lxcfs being installed should cause /proc/meminfo and /proc/cpuinfo in the container to report container values.

lxc info shows the values reported by the kernel memory cgroup, so those should be reliable, yes.