Using cAdvisor to Monitor Docker Containers

cAdvisor to monitor Docker containers

Google first created cAdvisor to monitor their own lmctfy containers and added Docker container support (those that use the default lib container execdriver). cAdvisor is short for Container Advisor. You can use cAdvisor to get a detailed look into the resource usage and the various performance characteristics of your running containers. cAdvisor includes a simple UI to view the live data, a simple API to retrieve the data programmatically, and the ability to store the data in an external InfluxDB.

We’ll be taking an introductory look into cAdvisor.

If you want to monitor all of the containers you have running on a host, you can deploy the cAdvisor image as a container in that same host. It will then have access to the resource usage and performance characteristics of your other containers in that host.

You can try out cAdvisor as long as you’re running Docker version 0.11 or above. Google has created a Docker image with everything you need to get started. You can do this by running:

sudo docker run \

–volume=/var/run:/var/run:rw \

–volume=/sys:/sys:ro \

–volume=/var/lib/docker/:/var/lib/docker:ro \

–publish=8080:8080 \

–detach=true \

–name=cadvisor \

google/cadvisor:latest

It’s that simple. If everything goes as expected you’ll now have another container running alongside your other Docker containers. You can check cAdvisor is running by pointing your browser to the host’s IP or hostname and port 8080. If running locally, try http://localhost:8080. This will bring up the built-in Web UI.

To put cAdvisor to a test we deployed a Unixbench Docker container alongside the cAdvisor container. To try that, you can simply execute:

docker run -d borja/unixbench

Below is a screenshot of what cAdvisor’s Web UI look like.

 

cAdvisor monitoring Docker container

 

This provides a high level overview of the resources being used on the host. Clicking on /docker in Subcontainers takes you to a new window with all of the Docker containers listed individually.

However, cAdvisor can be fairly limited in this capacity. It samples once a second with only 1 minute worth of historical data.

In order for this information to be useful we need to access this data programmatically. Luckily, cAdvisor exposes its raw and processed stats via a versioned remote REST API. This is accessible here:

http://<hostname>:<port>/

To access container information, the resource name is as follows:

/api/v1.1/subcontainers/

All of this container information is returned as a JSON object containing:

  • Absolute container name
  • List of subcontainers
  • ContainerSpec which describes the resource isolation enabled in the container
  • Detailed resource usage statistics of the container for the last N seconds (N is globally configurable in cAdvisor)
  • Histogram of resource usage from the creation of the container

We currently use our own in-house developed solution for monitoring at Tutum. However, we think cAdvisor is great, with active development, and a roadmap that excites us. We’re looking to integrate it with our system and contribute back to this exciting project in the Docker ecosystem.  Here are some features in its roadmap:

  • Advise on the performance of a container (e.g.: when it is being negatively affected by another, when it is not receiving the resources it requires, etc)
  • Auto-tune the performance of the container based on previous advise
  • Provide usage prediction to cluster schedulers and orchestration layers.

I wrote another article on how to use cAdvisor with Elasticsearch, Grafana and InfluxDB as part of a Panamax Application Template. This allows you to log and display the metrics cAdvisor collects, and the best part is that I’ve already done 90% of the work for you 🙂

Tagged with: , , ,
Posted in Tutorial
16 comments on “Using cAdvisor to Monitor Docker Containers
  1. Isaiah says:

    hi, Bryan, after I typed docker run -d borja/unixbench, everything is OK but I could not open http://localhost:8080 in my chrome, which said “The webpage is not avaialble”. Is there anything wrong happened?

    • Bryan Lee says:

      Did you make sure to run the cAdvisor container on port 8080? It has to be running alongside your other containers to be able to monitor them.

      • Isaiah says:

        Hi Bryan, I fixed it by mapping the port 8080 of my host to the port 8080 of the guest in the VirtualBox caused I used Mac OS X. Everything is OK now and thanks!

      • Bryan Lee says:

        Great! Glad it worked out. I’ll be posting up a blog post on using cAdvisor with Grafana, Elasticsearch, and InfluxDB soon. And stitching them all together with Panamax.io.

  2. […] had recently talked about using cAdvisor to monitor Docker containers. But as I mentioned, running cAdvisor provides ephemeral data for your containers. For this data to […]

  3. […] Imagine the value of this information for you : This machine (container) consumes a lot of network I/O and my application needs a lot of network I/O too,  I need to move my application to a different machine in the cluster or I need to spin up  more containers to balance the load. cAdvisor by Google is running daemon that collects, aggregates, processes, and exports information about running containers. A very interesting read about using cAdvisor to monitor Docker containers complete with a step by step guide can be found here. […]

  4. […] Imagine the value of this information for you : This machine (container) consumes a lot of network I/O and my application needs a lot of network I/O too,  I need to move my application to a different machine in the cluster or I need to spin up  more containers to balance the load. cAdvisor by Google is running daemon that collects, aggregates, processes, and exports information about running containers. A very interesting read about using cAdvisor to monitor Docker containers complete with a step by step guide can be found here. […]

  5. Dhiraj Kasliwal says:

    cadvisor monitor docker container for 1 min only. I need to increase monitor.graph shown time. How to do that?

  6. Swetha says:

    Can you brief about the terms in cadvisor UI like system slice and user slice etc.? all the recently created containers are shown only in system slice what is the reason behind that?

  7. […] Após a execução do comando, a página do cAdvisor estará disponível na porta 8080 do host. A página será parecida com essa (imagem retirada do excelente post "Using cAdvisor to Monitor Docker Containers": […]

  8. […] Imagine the value of this information for you: This machine (container) consumes a lot of network I/O and your application needs a lot of network I/O too. You need to move your application to a different machine in the cluster or you need to spin up more containers to balance the load. cAdvisor by Google is running daemon that collects, aggregates, processes and exports information about running containers. A very interesting read about using cAdvisor to monitor Docker containers complete with a step by step guide can be found here. […]

  9. weweave says:

    Thanks for this tutorial! After trying out cAdvisor, we decided to develop a little web-based monitoring solution ourselves. If want to give it a try, you can find the source and instructions on how to get the ready-to-run docker container on GitHub: https://github.com/weweave/docker-container-stats

  10. It’s apprоpriate time to mɑke a fᥱw plans fⲟr the lߋnger term аnd it’s timе tto bе happʏ.

    I have learn tҺiѕ post and if I ϲould Ⅰ desire to sugɡest үoᥙ some intereѕting issues or suggestions.
    Pеrhaps yоu could writе next articles relating tߋ this article.
    I wish to learn even mߋre issues aρproximately
    it!

  11. Hі! Quick question tһat’ѕ totally off topic. Ⅾo уou
    know hoԝ to mаke youг site mobile friendly?
    Ӎy web site ⅼooks weird աhen viewing ffrom my iphone4.
    ӏ’m trying to find a theme οr plugin that miցht bе
    аble to fix this problem. If you havᥱ aany suggestions, ρlease share.
    Аppreciate it!

  12. Ankit says:

    HI
    I am getting below error. Please guide me on this.

    sudo docker run volume=/var/run:/var/run:rw volume=/sys:/sys:ro volume=/var/lib/docker/:/var/lib/docker:ro publish=8080:8080 detach=true name=cadvisor google/cadvisor:latest
    [sudo] password for admin:
    /usr/bin/docker-current: Error parsing reference: “volume=/var/run:/var/run:rw” is not a valid repository/tag.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories
%d bloggers like this: