Tuesday, November 5, 2024
HomeDevOpsHow to Monitor Containers with cAdvisor

How to Monitor Containers with cAdvisor

cAdvisor (Container Advisor) provides container users an understanding of the resource usage and performance characteristics of their running containers. It is a running daemon that collects, aggregates, processes, and exports information about running containers. Specifically, for each container it keeps resource isolation parameters, historical resource usage, histograms of complete historical resource usage and network statistics. This data is exported by container and machine-wide.

cAdvisor has native support for Docker containers and should support just about any other container type out of the box. We strive for support across the board so feel free to open an issue if that is not the case. cAdvisor’s container abstraction is based on lmctfy‘s so containers are inherently nested hierarchically.

cAdvisor is a monitoring tool, open sourced by Google which can present the monitoring and performance data in various forms. cAdvisor run a daemon and collects the data per container and for overall host. This data can be consumed in the following ways:

  • cAdvisor web interface cAdvisor daemon exposes a web interface with graphs and performance data. Downside to this is that the historical data is not stored. The data presented is real time which makes it great for debugging.
  • Influxdb Influxdb is a time series database. cAdvisor can push the monitoring data to Influxdb where we can either query for the data by their client or manually build dashboards using Grafana or Chronograf.
  • Rest API cAdvisor also exposes a rest API which can be used to consume the monitoring data by adhoc applications and build logic over it.
  • Elasticsearch In pre-release version, we can use Elasticsearch to store the monitoring data.

cAdvisor can run on a host in two ways, as a standalone binary or as a Docker container. We will see both the ways in this post.

cAdvisor as a Standalone Binary

cAdvisor publishes standalone binaries on their release page. These binaries can be downloaded and run directly.

# wget https://github.com/google/cadvisor/releases/download/v0.26.1/cadvisor
# chmod 755 cadvisor
# ./cadvisor

By default, cAdvisor runs the web interface on port 8080. So, we will go on our browser and checkout the web interface at http://localhost:8080. Note that cAdvisor is aware of cgroups and namespaces. So, in addition to the containers, processes running on the hosts are also visible and can be monitored.

cAdvisor as a Docker Container

For environments where running a binary is not possible, cAdvisor provides a docker container which can be used to run the cAdvisor daemon.

# docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --publish=8080:8080 --detach=true --name=cadvisor1 google/cadvisor:latest

Note:  that on Red Hat, CentOS and Fedora, we may need to pass –privileged=true because of security measures enforced on the containers by SELinux (it is a good thing).

Now we can just browse the monitoring graphs at http://localhost:8080.

Read More: Monitor Docker Host Environment using Prometheus

Graphs:

Processes:

processes

CPU:

CPU Usage - cAdvisor

Memory:

memory - cAdvisor

Sub Containers:

sub containers - cAdvisor

Roadmap

cAdvisor aims to improve the resource usage and performance characteristics of running containers. Today, we gather and expose this information to users. In our 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.
RELATED ARTICLES
- Advertisment -

Most Popular

Recent Comments