Monitor Docker Containers resource usage with Ctop

Posted on 197 views

Have you been searching for a top like interface for container metrics and monitoring?. Ctop is a command line tool written to provide a concise and condensed overview of real-time metrics for containers running in your system. This command line tool comes with built-in support for both Docker and runC container engines.

Installing ctop on Linux / macOS

Ctop is written in Go and distributed as binary file which you can quickly download from Github and install it. Fetch the latest release for your platform and download with your wget or curl command.

Install ctop on Linux

For Linux systems we’ll download the binary file, extract and put in in the system PATH.

curl -s https://api.github.com/repos/bcicen/ctop/releases/latest | grep browser_download_url|grep linux-amd64 | cut -d '"' -f 4 | wget -i -
chmod +x ctop-*-linux-amd64
sudo mv ctop-*-linux-amd64 /usr/local/bin/ctop

Install ctop on macOS

If you’re running OS X, you can install ctop with brew or by downloading the latest pre-built binary file from Github.

Install ctop with brew:

brew install ctop

For manual package download, it is similar to below.

curl -s https://api.github.com/repos/bcicen/ctop/releases/latest | grep browser_download_url|grep darwin-amd64 | cut -d '"' -f 4 | wget -i -
chmod +x ctop-*-darwin-amd64
sudo mv ctop-*-darwin-amd64 /usr/local/bin/ctop

Confirm that is working.

$ ctop  --help
 Usage of ctop:
   -a    show active containers only
   -connector string
         container connector to use (default "docker")
   -f string
         filter containers
   -h    display this help dialog
   -i    invert default colors
   -r    reverse container sort order
   -s string
         select container sort field
   -scale-cpu
         show cpu as % of system total
   -v    output version information and exit

Running ctop

Using ctop is easy, just run the command ctop and you should get containers metrics displayed to you in realtime.

$ ctop

Sample output

top-command-docker-containers-1024x208

Ctop Keybindings

Key Action
Open container menu
a Toggle display of all (running and non-running) containers
f Filter displayed containers (esc to clear when open)
H Toggle ctop header
h Open help dialog
s Select container sort field
r Reverse container sort order
o Open single view
l View container logs (t to toggle timestamp when open)
S Save current configuration to file
q Quit ctop

Running ctop in Docker container

If you have big love for containers, you can run ctop in a docker container. But first install Docker in your system using the guide below,

Once docker is installed and running, spin up ctop container by running:

docker run --rm -ti \
  --name=ctop \
  -v /var/run/docker.sock:/var/run/docker.sock \
  quay.io/vektorlab/ctop:latest

 

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.