cAdvisor

tags: ITRI, cAdvisor, K8s

Ref: Community of 8bitmen > What is cAdvisor? How Does it Work? Explained…


1. What is cAdvisor?

It is container advisor. 從名字顯而易見:

  • It provides resource usage, performance characteristics & related information about the containers running on the cloud.
  • It is an open-source tool & runs as a daemon process in the background collecting, processing & aggregating useful DevOps information.
    • native support for Docker
    • enables us to track historical resource usage with histograms & stuff
Where Description
In Linux
  • Where the official cAdvisor releases are built
  • It has a small image size
  • In K8s
  • cAdvisor is integrated into the Kubelet binary
    • It is pretty intelligent to auto-discover all the containers running in the machine & collect CPU, memory, file system & network usage statistics.
  • It also provides a comprehensive overall machine usage by analyzing the root container.
  • 簡而言之,cAdvisor 要能夠協助拿到 metadata 並藉由其它可視化工具顯示出來。抽象化來看 cAdvisor 想要解決的問題是:

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    Now, what is a Kubelet? I’ve talked about it in the cAdvisor Kubernetes section up ahead in the article. So, stay tuned.


    1-1. How Do I Access the Container Data Collected by cAdvisor?

    cAdvisor 所收集的 data can be viewed with the help of:

    • web-based UI which it exposes at its port.
    • via a REST API

    1-2. cAdvisor 可以收集怎麼樣的 data 呢?

    • Container Information, typically
      • container name
      • list of sub-containers
      • container-spec
      • detailed usage statistics of the container for:
        • the last N seconds,
        • a histogram of resource usage, etc.
    • Machine Information
      • the number of schedulable logical core CPUs,
      • memory capacity in bytes,
      • maximum supported CPU frequency,
      • available file systems, network devices,
      • the machine topology – nodes, cores, threads etc.

    1-3. The Author's Experrience with cAdvisor

    The author worked on a massive e-Comm project where we used Grafana, Prometheus & cAdvisor to set up a dashboard monitoring system.

    • The dashboards were used to study the server instances, their uptime, exceptions, errors their contextual scenarios etc.

    1-4. Prometheus + Grafana using dashboard to show the data

    • All the data was displayed on custom Grafana dashboards.
    • Queries were fired from the dashboard which hit Prometheus, which was plugged-in to Grafana as a data source.

    Container information was streamed into Prometheus from cAdvisor.

    The below diagram shows the data flow between these open source tools, kind of a Grafana, Prometheus, cAdvisor based dashboard monitoring architectural flow.

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →


    2. How to Run cAdvisor With Docker?

    [Ref] Quick Start: Running cAdvisor in a Docker Container

    [shows] A single cAdvisor can be run to monitor the whole machine.

    Also, the tool is a static Go binary with no external dependencies. We can run it standalone if we wish to. The runtime behaviour can be controlled via a series of flags.

    cAdvisor also performs some housekeeping periodically. With these flags, we can control how & when the tool performs the task.


    3. Running cAdvisor With Prometheus

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    [Ref] Services and resources monitoring with Prometheus and Grafana running on Docker

    就是一個數據分析 (data analytics) 和監控 (monitoring) 的組合。

    • cAdvisorPrometheus 兩者各自做了什麼事?
      • cAdvisor exposes container statistics as metrics
      • Prometheus needs to config Job to connect with cAdvisor.

    Prometheus web-based UI

    It is used to get a more comprehensive view of things.

    Other examples to practice


    4. Running cAdvisor With Kubernetes by Heapster

    Kubernetes uses a project known as Heapster.

    • Heapster acts as a base monitoring platform. 也像其他的應用程式一樣在 k8s 上運行。
    • Heapster runs in Kubernetes pods & pulls data from Kubelets.
      • 它的 pod 能發現同一 cluster 下的所有 nodes.
    • It collects cluster-wide monitoring & event data.
      1. 然后從每一个 node 的 kubelet 中提取 metrics (一種度量標準)
      2. 並通過 pod 和 label 將其聚合起来
      3. 最後將其存儲到存儲系统或是監控服務中

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    [Ref] k8s 监控部署


    5. What is Kubelet?

    A Kubelet kind of manages things on the cluster.

    • It manages the pods & the containers on a machine.
    • It is responsible for fetching individual container usage statistics from cAdvisor.
      • The collected data is exposed via REST API
      • The entire data is saved in a data store such as InfluxDB & streamed to Grafana for visualization.

    **End**