Monitoring application containers

Treating a distributed application as a single unit makes it easier to monitor and trace problems. Docker Compose provides its own top and logs commands, which operate over all the containers in the application services and display the collected results.

To check the memory and CPU usage of all the components, run docker-compose top:

> docker-compose top

ch06-docker-compose_elasticsearch_1
Name PID CPU Private Working Set
---------------------------------------------------------
smss.exe 21380 00:00:00.046 368.6kB
csrss.exe 11232 00:00:00.359 1.118MB
wininit.exe 16328 00:00:00.093 1.196MB
services.exe 15180 00:00:00.359 1.831MB
lsass.exe 12368 00:00:01.156 3.965MB
svchost.exe 18424 00:00:00.156 1.626MB ...

Containers are listed in alphabetical order by name, and processes in each container are listed without a specific order. There's no way to change the ordering, so you can't show the most intensive processes in the hardest-working container first, but the result is in plain text, so you can manipulate it in PowerShell.

To see the log entries from all the containers, run docker-compose logs:

> docker-compose logs
Attaching to ch06-docker-compose_nerd-dinner-web_1, ch06-docker-compose_nerd-dinner-save-handler_1, ch06-docker-compose_nerd-dinner-api_1, ch06-docker-compose_nerd-dinner-db_1, ch06-docker-compose_kibana_1, ch06-docker-compose_nerd-dinner-index-handler_1, ch06-docker-compose_reverse-proxy_1, ch06-docker-compose_elasticsearch_1, ch06-docker-compose_nerd-dinner-homepage_1, ch06-docker-compose_message-queue_1

nerd-dinner-web_1 | 2019-02-12 13:47:11 W3SVC1002144328 127.0.0.1 GET / - 80 - 127.0.0.1 Mozilla/5.0+(Windows+NT;+Windows+NT+10.0;+en-US)+WindowsPowerShell/5.1.17763.134 - 200 0 0 7473
nerd-dinner-web_1 | 2019-02-12 13:47:14 W3SVC1002144328 ::1 GET / - 80 - ::1 Mozilla/5.0+(Windows+NT;+Windows+NT+10.0;+en-US)+WindowsPowerShell/5.1.17763.134 - 200 0 0 9718

...

On the screen, the container names are color-coded, so you can easily distinguish entries from different components. One advantage of reading logs through Docker Compose is that it shows output for all the containers, even if the component has shown errors and the container is stopped. These error messages are useful to see in contextyou may see that one component throws a connection error before another component logs that it has started, which may highlight a missing dependency in the Compose file.

Docker Compose shows all the log entries for all the service containers, so the output can be extensive. You can limit this with the --tail option, restricting the output to a specified number of the most recent log entries for each container.

These are useful commands when you are running in development or in a low-scale project with a single server running a small number of containers. It doesn't scale for large projects running on multiple containers across multiple hosts with Docker Swarm. For those, you need container-centric administration and monitoring, which I'll demonstrate in Chapter 8, Administering and Monitoring Dockerized Solutions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.188.138