Friday, May 22, 2015

Command Line Tool to Monitor Linux Containers Performance

http://linoxide.com/how-tos/monitor-linux-containers-performance

ctop is a new command line based tool available
to monitor the processes at the container level. Containers provide
operating system level virtualization environment by making use of the
cgroups resource management functionality. This tool collects data
related to memory, cpu, block IO and metadata like owner, uptime etc
from cgroups and presents it in a user readable format so that one can
quickly asses the overall health of the system. Based on the data
collected, it tries to guess the underlying container technology. ctop
is useful in detecting who is using large amounts of memory under low
memory situations.

Capabilities

Some of the capabilities of ctop are:

Collect metrics for cpu, memory and blkio

Gather information regarding owner, container technology, task count

Sort the information using any column

Display the information using tree view

Fold/unfold cgroup tree

Select and follow a cgroup/container

Select a timeframe for refreshing the displayed data

Pause the refreshing of data

Detect containers that are based on systemd, Docker and LXC

Advance features for Docker and LXC based containers

open / attach a shell for further diagnosis

stop / kill container types

Installation

ctop is written using Python and there
are no other external dependencies other than having to use Python
version 2.6 or greater (with built-in cursor support). Installation
using Python's pip is the recommended method. Install pip if not already
done and install ctop using pip.

Note: The examples shown in this article are from an Ubuntu (14.10) system

Usage options

Once you are inside the ctop screen, use the up (↑) and
down(↓) arrow keys to navigate between containers. Clicking on any
container will select that particular container. Pressing q or Ctrl+C
quits the container.

Let us now take a look at how to use each of the options listed above.

Note: At the time of writing this article, pip
repository did not have the latest version of ctop which supports
'--fold' option via command line.

--follow= - Follow/Highlight the cgroup path.

Eg: ctop --follow=/user.slice/user-1000.slice

As you can see in the screen below, the cgroup with the
given path "/user.slice/user-1000.slice" gets highlighted and makes it
easier for the user to follow it even when the display position gets
changed.

Output of 'ctop --follow'

You can also use the 'f' button to allow the highlighted line to follow the selected container. By default, follow is off.

--refresh= - Refresh the display at the given rate. Default 1 sec

This is useful in changing the refresh rate of the
display as per user requirement. Use the 'p' button to pause the
refresh and select the text.

--columns= - Can limit the display to
selected . 'name' should be the first entry followed by
other columns. By default, the columns include owner, processes,memory,
cpu-sys, cpu-user, blkio, cpu-time.

Eg: ctop --columns=name,owner,type,memory

Output of 'ctop --column'

-sort-col= - column using which the displayed data should be sorted. By default it is sorted using cpu-user

Eg: ctop --sort-col=blkio

If there are additional containers supported like Docker and LXC, following options will also be available:

press 'a' - attach to console output

press 'e' - open a shell in the container context

press 's' – stop the container (SIGTERM)

press 'k' - kill the container (SIGKILL)

ctop is
currently in active development by Jean-Tiare Le Bigot. Hopefully we
would see more features in this tool like our native top command :-).