- Linux:Powerful Server Administration
- Uday R. Sawant Oliver Pelz Jonathan Hobson William Leemans
- 414字
- 2021-07-09 18:17:04
Monitoring Docker containers
In this recipe, we will learn to monitor Docker containers.
How to do it…
Docker provides inbuilt monitoring with the docker stats
command, which can be used to get a live stream of the resource utilization of Docker containers.
- To monitor multiple containers at once using their respective IDs or names, use this command:
$ docker stats mysql f9617f4b716c
Tip
If you need to monitor all running containers, use the following command:
$ docker stats $(dockerps -q)
- With
docker logs
, you can fetch logs of your application running inside a container. This can be used similarly to thetail -f
command:$ docker logs -f ubuntu
- Docker also records state change events from containers. These events include start, stop, create, kill, and so on. You can get real-time events with
docker events
:$ docker events
To get past events, use the
--since
flag withdocker events
:$ docker events --since '2015-11-01'
- You can also check the changes in the container filesystem with the
docker diff
command. This will list newly added (A), changed (C), or deleted (D) files.$ docker diff ubuntu
- Another useful command is
docker top
, which helps look inside a container. This commands displays the processes running inside a container:$ docker top ubuntu
How it works…
Docker provides various inbuilt commands to monitor containers and the processes running inside them. It uses native system constructs such as namespaces and cgroups. Most of these statistics are collected from the native system. Logs are directly collected from running processes.
Need something more, possibly a tool with graphical output? There are various such tools available. One well-known tool is cAdvisor by Google. You can run the tool itself as a Docker container, as follows:
docker run -d -p 8080:8080 --name cadvisor \ --volume=/:/rootfs:ro \ --volume=/var/run:/var/run:rw \ --volume=/sys:/sys:ro \ --volume=/var/lib/docker/:/var/lib/docker:ro \ google/cadvisor:latest
Once the container has been started, you can access the UI at your server domain or IP on port 8080
or any other port that you use. cAdvisor is able to monitor both LXC and Docker containers. In addition, it can report host system resources.
There's more…
Various external tools are available that provide monitoring and troubleshooting services. Sysdig is a similar command-line tool that can be used to monitor Linux systems and containers. Read some examples of using sysdig at https://github.com/draios/sysdig/wiki/Sysdig%20Examples.
Also, check out Sysdig Falco, an open source behavioral monitor with container support.
See also
- Docker runtime metrics at http://docs.docker.com/v1.8/articles/runmetrics/
- cAdvisor at GitHub: https://github.com/google/cadvisor
- 大數(shù)據(jù)戰(zhàn)爭(zhēng):人工智能時(shí)代不能不說(shuō)的事
- 嵌入式系統(tǒng)應(yīng)用
- 輕松學(xué)C#
- 網(wǎng)上沖浪
- 條碼技術(shù)及應(yīng)用
- 自主研拋機(jī)器人技術(shù)
- 工業(yè)控制系統(tǒng)測(cè)試與評(píng)價(jià)技術(shù)
- Machine Learning with Apache Spark Quick Start Guide
- Python:Data Analytics and Visualization
- Applied Data Visualization with R and ggplot2
- 工業(yè)機(jī)器人實(shí)操進(jìn)階手冊(cè)
- 計(jì)算機(jī)硬件技術(shù)基礎(chǔ)(第2版)
- 人工智能云平臺(tái):原理、設(shè)計(jì)與應(yīng)用
- 納米集成電路制造工藝(第2版)
- 單片機(jī)C51應(yīng)用技術(shù)