ctop – Top-like Interface for Monitoring Docker Containers


If you are managing multiple Docker containers, it can be challenging to keep track of their resource utilization, network connectivity, and overall health. Fortunately, there's a tool called ctop that can help. ctop is a top-like interface for monitoring Docker containers in real-time. It provides an intuitive visual representation of container metrics, including CPU, memory, network, and disk usage.

In this blog post, we'll take a closer look at ctop, its features, and how to use it effectively.

What is ctop?

ctop is a command-line tool that provides a top-like interface for monitoring Docker containers. It provides an overview of all running containers, displaying real-time CPU and memory usage, container name, image, and ID. ctop also allows you to sort and filter the container list based on different criteria, such as CPU usage or container name.

Installing ctop

ctop is an open-source tool that can be installed on Linux, macOS, and Windows. You can download the latest version of ctop from the GitHub repository: https://github.com/bcicen/ctop/releases.

To install ctop on Linux, follow these steps −

  • Download the ctop binary for Linux from the GitHub release page −

$ wget https://github.com/bcicen/ctop/releases/download/v0.7.6/ctop-0.7.6-linux-amd64 -O ctop
  • Make the binary executable −

$ chmod +x ctop
  • Move the binary to a location in your $PATH −

$ sudo mv ctop /usr/local/bin/
  • Verify that ctop is installed correctly by running −

$ ctop -v

You should see the version of ctop printed on the console.

Using ctop

ctop is a command-line tool that runs in your terminal. When you start ctop, you'll see a live view of your Docker containers with their resource utilization metrics. You can sort the containers by various criteria, such as CPU usage, memory usage, network traffic, and more.

Here's an example of running ctop with the default settings −

$ ctop

This will display a live view of your Docker containers, sorted by their CPU usage. You can use the arrow keys to navigate between containers and view their metrics.

To sort the containers by a different criterion, press the corresponding shortcut key −

  • m − Sort by memory usage

  • n − Sort by network traffic

  • i − Sort by container ID

  • s − Sort by container status

  • p − Sort by container PIDs

  • c − Sort by container CPU usage (default)

You can also use filters to narrow down the list of containers based on certain criteria. For example, you can filter the containers by name or label −

$ ctop -f name=web

This will display only the containers whose name contains "web". Similarly, you can filter the containers by label −

$ ctop -f label=com.example.app=frontend

This will display only the containers that have the label "com.example.app" with the value "frontend".

ctop also provides detailed information about each container, including its resource utilization metrics, running processes, and environment variables. To view the container details, highlight the container using the arrow keys and press Enter.

Here's an example of viewing the details of a container −

  • First, launch ctop in your terminal −

$ ctop
  • ctop will display a list of running Docker containers, along with their resource utilization metrics.

NAME           CPU%    MEM USAGE / LIMIT     MEM%    NET I/O            BLOCK I/O   PIDS
my-container   1.13%   66.26MiB / 3.697GiB   1.76%   14.57kB / 2.03kB   6.97MB / 16.4MB   1/1
  • Use the arrow keys to highlight the container you want to inspect.

my-container  1/1  2.13%  66.26MiB / 3.697GiB  1.76%  14.57kB / 2.03kB  6.97MB / 16.4MB running
  • Press Enter to view the details of the selected container.

Container ID: 28c54bfc07f4
Image: alpine:latest
Command: /bin/sh -c sleep 3600
Status: running for 2 hours
Created: 1 day ago
IP: 172.17.0.3
Networks: bridge

CPU:
  Usage: 0.0%
  System: 33s
  User: 1m50s

Memory:
  Usage: 66.26MiB / 3.697GiB
  Percentage: 1.76%

Network:
  Input: 14.57kB
  Output: 2.03kB

Block IO:
  Input: 6.97MB
  Output: 16.4MB

Processes:
  Running: 1
  Total: 1
  • Use the arrow keys to navigate the detailed container information and press Esc to exit the detailed view and return to the main ctop interface.

NAME           CPU%    MEM USAGE / LIMIT     MEM%    NET I/O       BLOCK I/O   PIDS
my-container   1.13%   66.26MiB / 3.697GiB   1.76%   14.57kB / 2.03kB   6.97MB / 16.4MB   1/1

Customizing ctop

ctop provides several options for customizing the interface and behavior of the tool. Here are some examples −

  • Sorting containers by resource usage − By default, ctop sorts containers by name. You can change the sorting order by pressing the corresponding key (e.g., "p" for sorting by CPU usage or "m" for sorting by memory usage

  • Filtering containers − You can filter containers by name or ID by pressing "f" and entering the filter criteria.

  • Changing the color scheme − ctop provides several color schemes that can be switched by pressing "t". You can also customize the color scheme by creating a configuration file in ~/.config/ctop/colors.toml.

  • Setting resource limits − You can set resource limits for CPU, memory, and block I/O by pressing "l" and entering the limit values.

To view the full list of options and keybindings, press "?".

Advanced ctop features to consider

While ctop is a simple and easy-to-use tool, it also offers some advanced features that can help you better monitor your containers.

  • Sorting and Filtering − ctop allows you to sort and filter your container list based on different criteria, such as CPU usage or container name. This can help you quickly identify containers that are using the most resources or those that are experiencing issues. You can sort the container list by pressing the corresponding key ('c' for CPU usage, 'm' for memory usage, etc.) or filter by container name by pressing the '/' key followed by the container name.

  • Customizing the Interface − ctop allows you to customize the interface by choosing which columns to display and how they are displayed. This can help you tailor the interface to your specific needs and preferences. You can customize the columns displayed by pressing the 'f' key and selecting the desired columns.

  • Keyboard Shortcuts − ctop supports keyboard shortcuts for many common tasks, such as sorting the container list, filtering by name, and viewing container logs. This can help you quickly navigate the interface and perform tasks more efficiently. You can access the list of available keyboard shortcuts by pressing the '?' key.

Overall, ctop is a powerful tool that provides real-time monitoring of Docker containers. Its simple yet feature-rich interface makes it an excellent choice for anyone who needs to manage and monitor containers.

Conclusion

ctop is a powerful tool for monitoring and managing Docker containers in real-time. Its top-like interface and detailed container metrics make it easy to identify and troubleshoot container issues, optimize resource utilization, and ensure the smooth operation of your Docker infrastructure. With its customizable interface and numerous options for filtering and sorting containers, ctop is a versatile tool that can be tailored to your specific needs. Whether you're a Docker power user or just getting started with containerization, ctop is a must-have tool in your toolbox.

Updated on: 23-Jun-2023

417 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements