Data Centers

How to monitor your Docker containers with ctop

Jack Wallen shows you how to install, and use ctop for quick and easy container monitoring on a Linux Docker server.

dockerhero.jpg
Image: Jack Wallen

If Docker is your container service of choice, you know how easy it is to create and deploy containers. Chances are you've already done so and have numerous containers running on your network. However, do you know how well those containers are performing? If you're familiar with Linux, you might wish there were an top/htop app geared specifically for containers.

There is.

That's right, one of the best means of monitoring your containers is an open source tool, found on Github, called ctop. With this app, you can get a quick overview of your containers, their names, IDs, and how much CPU, Memory, and Network Rx/Tx data. Ctop even allows you to filter what you're viewing, and gives you an expanded view of a selected container. Although it may not offer a massive amount of features, it does the job and does it well. The tool is easy to install, and even easier to use. I'll demonstrate on a Ubuntu 16.04 platform, but ctop can be installed on nearly any Linux distribution.

Installation

There are two ways to install ctop: As an app or a container. I'll show you both. First, we'll install ctop as a container. To do this, log into your container server and issue the following command to deploy the container:

docker run -ti -v /var/run/docker.sock:/var/run/docker.sock quay.io/vektorlab/ctop:latest

The above command will pull down the necessary image, deploy the container, and drop you into the app. To exit ctop, hit [Ctl]+[x]. The problem with using ctop in this manner is that you must issue the above command every time you wish to run ctop. That's too much typing. Let's make it easier.

We can install ctop as a local application. To do so, we'll pull down the executable from Github, move it into /usr/local/bin, and give it the necessary permissions with the following commands:

wget https://github.com/bcicen/ctop/releases/download/v0.4.1/ctop-0.4.1-linux-amd64 -O ctop
sudo mv ctop /usr/local/bin/
sudo chmod +x /usr/local/bin/ctop

At this point, you can start up ctop anytime with the command ctop.

Usage

Using ctop is simple. Once you have the tool open (Figure A), you'll see all of your currently active containers listed.

Figure A

Figure A

Three containers are running and displaying their usage.

As you can see, one of my containers (wonderful_stallman) is using 1.37GB of memory. That particular container is an instance of Only Office, so it makes sense it would be using a larger amount of resources. However, it's nearly hogging up all of the system resources on my virtual machine, so I might want to consider migrating that container to a beefier virtual machine.

With ctop, you can easily filter your containers. Say you have a large number of containers on your server and want to check on the resource usage of a particular deployment. With ctop open, hit the f key on your keyboard to open the filter (Figure B).

Figure B

Figure B

The filter is ready for you.

Type the name of a container and ctop will display only the results that match the filter. This is incredibly helpful when your Docker server hosts numerous containers. To clear a filter, type f again, and then hit Enter on the keyboard.

If you select a container from the listing and hit Enter, you will see a bit more information laid out in easy to read graphs (Figure C).

Figure C

Figure C

Expanded information about my OnlyOffice container.

To exit out of the expanded view, type q. To exit out of ctop, type q, and you'll be returned to your bash prompt.

Just enough info

And that's pretty much the gist of using ctop on Linux for viewing details of your containers. This tool doesn't offer extensive information, but it will give you just enough information to keep you aware of how your containers are performing. Ctop could easily be a first line of defense in troubleshooting Docker containers.

Also see

About Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.

Editor's Picks

Free Newsletters, In your Inbox