Wednesday, July 3, 2024
HomeServerMonitoring & ManagementMonitor Docker Containers resource usage with Ctop

Monitor Docker Containers resource usage with Ctop

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

Ctop Keybindings

Key Action
<enter> 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

Other interesting container articles.

How to Optimize Linux System with Stacer

How to Deploy and Use Dokku on Ubuntu

How to Install Minikube on Ubuntu / Debian

Install Docker and Docker Compose on Linux Mint

How to run Docker Containers on Windows Server 2019

How to setup 3 node Kubernetes Cluster on Ubuntu with Weave Net CNI

Thapelo Manthata
I’m a desktop support specialist transitioning into a SharePoint developer role by day and Software Engineering student by night. My superpowers include customer service, coding, the Microsoft office 365 suite including SharePoint and power platform.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments