Monitoring Docker Containers using cAdvisor

In this article, we are going to monitor the Docker container’s performance characteristics and resource usage using cAdvisor.

cAdvisor (Container Advisor) monitors both Docker host and containers.

Before setting up the cAdvisor, let see the existing infrastructure as below,

We are using Docker host server named ‘docker-host-1 / 192.168.0.34’

# docker ps -> list out the running docker containers,

[root@docker-host-1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0328aa865e10 progrium/stress "/usr/bin/stress --v…" 16 seconds ago Up 15 seconds stupefied_mcnulty
a03199172063 nginx "nginx -g 'daemon of…" About a minute ago Up About a minute 80/tcp test-nginx
[root@docker-host-1 ~]#

Here, two containers ‘stupefied_mcnulty‘ and ‘test-nginx‘ are in running state from images of ‘progrium/stress‘ and ‘nginx‘ respectively.

To install and run cAdvisor as a container on docker host, please use the below command,

# docker run \
–volume=/:/rootfs:ro \
–volume=/var/run:/var/run:rw \
–volume=/sys:/sys:ro \
–volume=/var/lib/docker/:/var/lib/docker:ro \
–volume=/dev/disk/:/dev/disk:ro \
–volume=/cgroup:/cgroup:ro \
–publish=8080:8080 \
–detach=true \
–name=cadvisor \
–privileged=true \
google/cadvisor:latest

 

[root@docker-host-1 ~]# docker run \
> --volume=/:/rootfs:ro \
> --volume=/var/run:/var/run:rw \
> --volume=/sys:/sys:ro \
> --volume=/var/lib/docker/:/var/lib/docker:ro \
> --volume=/dev/disk/:/dev/disk:ro \
> --volume=/cgroup:/cgroup:ro \
> --publish=8080:8080 \
> --detach=true \
> --name=cadvisor \
> --privileged=true \
> google/cadvisor:latest
Unable to find image 'google/cadvisor:latest' locally
latest: Pulling from google/cadvisor
ab7e51e37a18: Pull complete
a2dc2f1bce51: Pull complete
3b017de60d4f: Pull complete
Digest: sha256:9e347affc725efd3bfe95aa69362cf833aa810f84e6cb9eed1cb65c35216632a
Status: Downloaded newer image for google/cadvisor:latest
5d6a39b5adc563603fdab59a0f22af17fb4c8f7a51db3cba55452289c39c4070
[root@docker-host-1 ~]#

Now we can see, cAdvisor contianer is running as below,

[root@docker-host-1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
527eed602bc4 progrium/stress "/usr/bin/stress --v…" 19 seconds ago Up 19 seconds tender_shirley
5d6a39b5adc5 google/cadvisor:latest "/usr/bin/cadvisor -…" 47 seconds ago Up 45 seconds 0.0.0.0:8080->8080/tcp cadvisor
a03199172063 nginx "nginx -g 'daemon of…" 19 minutes ago Up 19 minutes 80/tcp test-nginx
[root@docker-host-1 ~]#

we can access the cAdvisor’s web user interface(UI) via http://localhost:8080 or http://192.168.0.34:8080
This Web UI dashboard will shows last 1 minute data,

Lets grab the screenshot from that web UI as below,

Usage meter:

Process utilization:

CPU utilization:

 

Memory utilization:

Network Utilization:

Filesystem utilization:

 

So by using cAdvisor as container in Docker host, we can see the performance metrics for last 1 minute and it is a run time data.