Ctop: a command line artifact that monitors the performance of Linux containers
Ctop is a new command line-based tool that can be used to monitor processes at the container level. By using the resource management function of the controller group (cgroup), containers provide a virtual environment at the operating system level. The tool collects data related to memory, CPU, block input and output, as well as the owner, boot time, and other metadata from the cgroup, and presents the data to users in a user-friendly format, in this way, the System Health status can be quickly evaluated. Based on the obtained data, it can try to speculate the lower-layer container technology. Ctop also helps to detect who is consuming a large amount of memory in a low-memory environment.
Function
Some functions of ctop are as follows:
- Collect metric values of CPU, memory, and block input/output
- Collect information related to owner, container technology, and task statistics
- Sort information by any column
- Display information in a tree view
- Collapse/expand cgroup tree
- Select and track cgroup/Container
- Select the display time window for data refresh
- Pause refreshing data
- Detect containers based on systemd, Docker, and LXC
- Advanced features of Docker and LXC-based containers
- Open/connect to shell for deep Diagnosis
- Stop/kill container type
Install
Ctop is written in Python, so there is no external dependency except Python 2.6 or later (with built-in cursor support. We recommend that you use Python pip for installation. If you have not installed pip, install it first and then use pip to install ctop.
Note: The sample code in this article is from the Ubuntu (14.10) system.
$ sudo apt-get install python-pip
Use pip to install ctop:
poornima@poornima-Lenovo:~$ sudo pip install ctop
[sudo] password for poornima:
Downloading/unpacking ctop
Downloading ctop-0.4.0.tar.gz
Running setup.py (path:/tmp/pip_build_root/ctop/setup.py) egg_info forpackage ctop
Installing collected packages: ctop
Running setup.py install for ctop
changing mode of build/scripts-2.7/ctop from644 to 755
changing mode of /usr/local/bin/ctop to 755
Successfully installed ctop
Cleaning up...
If you do not select pip for installation, you can also use wget to install it directly from github:
poornima@poornima-Lenovo:~$ wget https://raw.githubusercontent.com/yadutaf/ctop/master/cgroup_top.py -O ctop
--2015-04-2919:32:53-- https://raw.githubusercontent.com/yadutaf/ctop/master/cgroup_top.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)...199.27.78.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|199.27.78.133|:443... connected.
HTTP request sent, awaiting response...200 OK Length:27314(27K)[text/plain]
Saving to: ctop
100%[======================================>]27,314--.-K/s in0s
2015-04-2919:32:59(61.0 MB/s)- ctop saved [27314/27314]
poornima@poornima-Lenovo:~$ chmod +x ctop
If the cgroup-bin package is not installed, you may encounter an error message. You can solve this problem by installing the required package.
poornima@poornima-Lenovo:~$ ./ctop
[ERROR]Failed to locate cgroup mountpoints.
poornima@poornima-Lenovo:~$ sudo apt-get install cgroup-bin
The following is an example of ctop output:
Ctop Screen
Usage options
ctop [--tree][--refresh=][--columns=][--sort-col=][--follow=][--fold=,...] ctop (-h |--help)
When you enter the ctop screen, you can use the upper and lower arrow keys to navigate between containers. Click a container and select the container. Press q or Ctrl + C to exit the container.
Now, let's take a look at how the various options listed above are used.
-H/-- help-display the help letter
poornima@poornima-Lenovo:~$ ctop -h
Usage: ctop [options]
Options:
-h,--help show this help message andexit
--tree show tree view bydefault
--refresh=REFRESH Refresh display every <seconds>
--follow=FOLLOW Follow cgroup path
--columns=COLUMNS List of optional columns to display.Always includes
'name'
--sort-col=SORT_COL Select column to sort by initially.Can be changed
dynamically.
-- Tree-display the container tree View
By default, the List View is displayed.
When you enter the ctop window, you can use the F5 button to switch between tree/list views.
-- Fold =-collapse the cgroup path named <name> in the Tree View
This option must be combined with the -- tree option.
Example: ctop -- tree -- fold =/user. slice
Output of 'ctop -- fold'
In the ctop window, use the +/-Key to expand or collapse the child cgroup.
Note: When writing this text, the pip repository does not have the latest ctop version, and the '-- fold' option of the command line is not supported.
-- Follow =-trace/highlight cgroup path
Example: ctop -- follow =/user. slice/user-1000.slice
As you see on the screen below, cgroups with the "/user. slice/user-1000.slice" path are highlighted, making it easy for users to track, even if the display position changes.
'Ctop -- follow' output
You can also use the 'F' button to track selected containers with highlighted rows. By default, tracing is disabled.
-- Refresh =-refresh the display at the specified frequency. The default value is 1 second.
This is useful when you change the update rate based on your needs. You can use the 'p' button to pause refreshing and select text.
-- Columns =-only the selected columns are displayed. 'Name' must be the first field followed by other fields. By default, fields include: owner, processes, memory, cpu-sys, cpu-user, blkio, cpu-time
Example: ctop -- columns = name, owner, type, memory
'Ctop -- column 'output
-Sort-col =-sort by specified column. Cpu-user sorting by default
Example: ctop -- sort-col = blkio
If there are additional containers supported by Docker and LXC, the tracking options are also available:
Press 'a'-connect to terminal output
Press 'e'-open a shell in the container
Press's-Stop container (SIGTERM)
Press 'K'-SIGKILL)
Currently, Jean-Tiare Le Bigot is still actively developing ctop. We hope we can see the same features as the local top Command in this tool :-)
This article permanently updates the link address: