The container monitor – cadvisor

The containers have been wild used in a lot of places, but how the operators know the data like CPU, memory, network. The answer is cadvisor.

docker stats and cadvisor

As you know, the dokcer stats can check the status of Docker container like:

CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT    MEM %               NET I/O             BLOCK I/O           PIDS
a25dd77a5237        cadvisor            0.91%               14.8MiB / 1.952GiB   0.74%               749kB / 11.5MB      18.9MB / 0B         11

But you can not get data through HTTP and there was no panel for it.

With all these issues of dokcer stats ,  here comes cadvisor to deal with them.  You not only can usecadvisor to collect all the information of a container but also provide a way to let Prometheus display on UI.

So, the cadvisor is your first choice as container monitor.

How to install cadvisor

Step1: use docker pull to get the latest cadvisor

$ docker pull google/cadvisor:latest

Step2: use docker images to check the image version (optional)

$ docker images  

google/cadvisor      latest              75f88e3ec333        4 months ago        62.2MB

Step3:  docker run the images

sudo 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 \
  --publish=8080:8080 \
  --detach=true \
  --name=cadvisor \
  google/cadvisor:latest

with docker ps you will get the information

CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                    NAMES
742a464fa631        google/cadvisor:latest   "/usr/bin/cadvisor -…"   1 second ago        Up 1 second         0.0.0.0:8080->8080/tcp   cadvisor

Step4: Vistit http://localhost:8080 :

/images/cadvisor/cadvisor-01.png

Congratulations!

Deep into cadvisor

Tips1: visit http://localhost:8080/docker you can check all the docker containers you have:

/images/cadvisor/cadvisor-02.png

Tips2: get the detail information by click one of them.

/images/cadvisor/cadvisor-03.png

/images/cadvisor/cadvisor-04.png

Tips3: Visit http://localhost:8080/metrics you can check all the data passed to  Prometheus :

/images/cadvisor/cadvisor-05.png

In conclusion:

Cadvisor is an awesome tool to collect and query data of container.

We will talking about how to use Prometheus and Grafana to monitor and alert next time.

Leave a comment