Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ctop to test Linux container performance on the command line

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to use ctop to test the performance of Linux containers on the command line". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor learn how to use ctop to test the performance of Linux containers on the command line.

Ctop is a new command line-based tool that can be used to monitor processes at the container level. The container provides a virtualized environment at the operating system level by leveraging the resource management capabilities of the Controller Group (cgroup). The tool collects data related to memory, CPU, block input and output from cgroup, as well as metadata such as owner and boot time, and presents it to users in a user-friendly format, so that the health of the system can be quickly evaluated. Based on the data obtained, it can try to speculate about the underlying container technology. Ctop also helps to detect who is consuming a lot of memory in low-memory environments.

Function

Some features of ctop are as follows:

Collect metrics for CPU, memory, and block input and output

Collect information related to owner, container technology, and task statistics

Sort the information through any column

Display information in a tree view

Collapse / expand the cgroup tree

Select and track cgroup/ containers

Select the time window to display the data refresh

Pause refresh data

Detect containers based on systemd, Docker, and LXC

Advanced features of containers based on Docker and LXC

Open / connect shell for deep diagnostics

Stop / kill container type

Installation

Ctop is written by Python, so there are no external dependencies other than Python 2.6 or later (with built-in cursor support). It is recommended to use Python's pip for installation. If you have not already installed pip, install it first, and then use pip to install ctop.

Note: the sample of this article is from Ubuntu (14.10) system.

The code is as follows:

$sudo apt-get install python-pip

Install ctop using pip:

The code is as follows:

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 for package ctop

Installing collected packages: ctop

Running setup.py install for ctop

Changing mode of build/scripts-2.7/ctop from 644 to 755

Changing mode of / usr/local/bin/ctop to 755

Successfully installed ctop

Cleaning up...

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

The code is as follows:

Poornima@poornima-Lenovo:~$ wget https://raw.githubusercontent.com/yadutaf/ctop/master/cgroup_top.py-O ctop

-- 2015-04-29 1914 32 Rose 53 muri-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

27314 [= >] 100% [= >] 100% [= >] 100% [= >] 27314 -.-KUnip s in 0s

2015-04-29 19:32:59 (61.0 MB/s)-ctop saved [273140.27314]

Poornima@poornima-Lenovo:~$ chmod + x ctop

If the cgroup-bin package is not installed, you may get an error message that you can fix by installing the required package.

Poornima@poornima-Lenovo:~$. / ctop

[ERROR] Failed to locate cgroup mountpoints.

Poornima@poornima-Lenovo:~$ sudo apt-get install cgroup-bin

Here is a sample output from ctop:

Ctop screen

Usage option

Ctop [--tree] [--refresh=] [--columns=] [--sort-col=] [--follow=] [--fold=,...] Ctop (- h |-- help)

When you enter the ctop screen, use the up (↑) and down (↓) arrow keys to navigate between containers. Click on a container to select the container and press Q or Ctrl+C to exit the container.

Now, let's take a look at how the list of options above works.

-h /-- help-displays help information

Poornima@poornima-Lenovo:~$ ctop-h

Usage: ctop [options]

Options:

-h,-- help show this help message and exit

-- tree show tree view by default

-- refresh=REFRESH Refresh display every

-- 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-displays the tree view of the container

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=-collapses the cgroup path named in the tree view

This option needs to be combined with the-- tree option.

Example: ctop-- tree-- fold=/user.slice

'ctop-- the output of fold'

In the ctop window, use the + /-key to expand or collapse the child cgroup.

Note: at the time of this writing, the latest version of ctop is not available in the pip repository and the command line'--fold' option is not supported.

-- follow=-track / highlight cgroup path

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

As you can see on the following screen, the cgroup with the "/ user.slice/user-1000.slice" path is highlighted, which makes it easy for the user to track, even if the display location changes.

'ctop-- the output of follow'

You can also use the'f 'button to let the highlighted lines track the selected container. By default, tracing is off.

-- refresh=-refreshes the display at the specified frequency. Default is 1 second.

This is useful when changing the refresh rate according to the needs of each user. Use the'p 'button to pause the refresh and select the text.

-- columns=-restricts the display of only the selected columns.' Name' needs to 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-- the output of column'

-sort-col=-sorts by the specified column. Cpu-user sorting is used by default

Example: ctop-- sort-col=blkio

Tracking options are also available if there are additional containers supported by Docker and LXC:

Press 'a'-connect to terminal output

Press 'e'-Open a shell in the container

Press's'- stop container (SIGTERM)

Press 'k'-Kill the container (SIGKILL)

At present, Jean-Tiare Le Bigot is still actively developing ctop. I hope we can see the same features as the native top command in this tool: -)

At this point, I believe you have a deeper understanding of "how to use ctop to test the performance of Linux containers on the command line". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report