Ctop: a command line artifact that monitors the performance of Linux containers

Source: Internet
Author: User
Tags virtual environment

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.

  1. $ sudo apt-get install python-pip

Use pip to install ctop:

  1. poornima@poornima-Lenovo:~$ sudo pip install ctop
  2. [sudo] password for poornima:
  3. Downloading/unpacking ctop
  4. Downloading ctop-0.4.0.tar.gz
  5. Running setup.py (path:/tmp/pip_build_root/ctop/setup.py) egg_info forpackage ctop
  6. Installing collected packages: ctop
  7. Running setup.py install for ctop
  8. changing mode of build/scripts-2.7/ctop from644 to 755
  9. changing mode of /usr/local/bin/ctop to 755
  10. Successfully installed ctop
  11. Cleaning up...

If you do not select pip for installation, you can also use wget to install it directly from github:

  1. poornima@poornima-Lenovo:~$ wget https://raw.githubusercontent.com/yadutaf/ctop/master/cgroup_top.py -O ctop
  2. --2015-04-2919:32:53-- https://raw.githubusercontent.com/yadutaf/ctop/master/cgroup_top.py
  3. Resolving raw.githubusercontent.com (raw.githubusercontent.com)...199.27.78.133
  4. Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|199.27.78.133|:443... connected.
  5. HTTP request sent, awaiting response...200 OK Length:27314(27K)[text/plain]
  6. Saving to: ctop
  7. 100%[======================================>]27,314--.-K/s in0s
  8. 2015-04-2919:32:59(61.0 MB/s)- ctop saved [27314/27314]
  1. 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.

  1. poornima@poornima-Lenovo:~$ ./ctop
  2. [ERROR]Failed to locate cgroup mountpoints.
  3. poornima@poornima-Lenovo:~$ sudo apt-get install cgroup-bin

The following is an example of ctop output:

Ctop Screen

 

Usage options
  1. 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

  1. poornima@poornima-Lenovo:~$ ctop -h
  2. Usage: ctop [options]
  3. Options:
  4. -h,--help show this help message andexit
  5. --tree show tree view bydefault
  6. --refresh=REFRESH Refresh display every <seconds>
  7. --follow=FOLLOW Follow cgroup path
  8. --columns=COLUMNS List of optional columns to display.Always includes
  9. 'name'
  10. --sort-col=SORT_COL Select column to sort by initially.Can be changed
  11. 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:

  1. Press 'a'-connect to terminal output
  2. Press 'e'-open a shell in the container
  3. Press's-Stop container (SIGTERM)
  4. 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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.