How to find out information about a LXC (Linux container) CPU & Memory Usage

last updated in Categories , , ,

How can I find out information about a Linux container (LXC) such as CPU usage and memory usage from the command prompt? Is there is top command like a tool for lxc to monitor memory and cpu usage?

You need to use the lxc-info command to display the following information about a LXC:

  1. CPU usage in seconds.
  2. Block I/O usage.
  3. Memory usage.
  4. Kmem (kernel memory) usage.
  5. Networking TX/RX usage.

lxc-info syntax and example

The syntax is:

lxc-info -n {container-name-here}
lxc-info [options] -n {container-name-here}

To display information for cyberciti container, enter:

# lxc-info -n cyberciti

Fig.01: lxc-info in action
Fig.01: lxc-info in action

Show information for all containers whose name starts with nixcraft, run:

# lxc-info -n 'nixcraft.*'

Just print the container’s state

# lxc-info -s -n lxcdb

Just print the container’s pid

# lxc-info -p -n lxmemcache

ust print the container’s IP addresses

# lxc-info -i -n lxnginx

Say hello to lxc-top

You can use the lxc-top command to monitor container statistics. The output is updated every 3 seconds and is ordered according to the sortby value given by the user. The syntax is:

lxc-top
lxc-top [options]

Set amount of time in seconds to delay between screen updates:
# lxc-top --delay 5
To Sort the containers by name, cpu use, or memory use. The sortby argument should be one of the letters n,c,b,m,k to sort by name, cpu use, block I/O, memory, or kernel memory use respectively. The default is ‘n’.
# lxc-top --sort {sortby}
## [ CPU usage ]
# lxc-top --sort c
## [ memory usage ]
# lxc-top --sort m

htop cgroup option

First, install htop on a Linux operating system using the yum or apt-get:
$ sudo apt-get install htop
OR
$ sudo yum install htop
Start the htop, enter:
# htop
Press F2 special key to enter into setup mode. Choose SETUP > Columns > Choose CGGROUP from Available Columns > Press F10 to save the changes:

Fig.02: Display htop cgroups columns on a Linux
Fig.02: Display htop cgroups columns on a Linux

You should see output as follows:
Fig.03: htop in action
Fig.03: htop in action

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Share this on (or read 2 comments/add one below):

2 comment

    Have a question? Post it on our forum!