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

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

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 [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
$ 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

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

Posted by: SXI ADMIN

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.


How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....

How to Start and Enable Firewalld on CentOS 7

In this article, we discuss how to start and enable firewalld. It is highly recommended that you have a firewall protecting your server.Pre-Flight CheckThese...