How to find out information about a LXC (Linux container) CPU & Memory Usage
H
ow 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:
CPU usage in seconds.
Block I/O usage.
Memory usage.
Kmem (kernel memory) usage.
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
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
You should see output as follows:
Fig.03: htop in action