cAdvisor
使用 cAdvisor
cAdvisor 是 Google 開源的一款用於展示和分析容器運行狀態的可視化工具。
通過在主機上運行 cAdvisor 用戶可以輕松的獲取到當前主機上容器的運行統計信息,並以圖表的形式向用戶展示。
在本地運行 cAdvisor 也非常簡單,直接運行一下命令即可:
VERSION=v0.36.0 # use the latest release version from https://github.com/google/cadvisor/releases
docker run \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--publish=20000:8080 \
--detach=true \
--name=cadvisor \
--restart=always \
--privileged \
--device=/dev/kmsg \
gcr.io/google-containers/cadvisor:$VERSION
通過瀏覽 http://localhost:8080 可以查看,當前主機上容器的運行狀態,如下所示:
cAdvisor 是一個簡單易用的工具,相比於使用 Docker 命令行工具,用戶不用再登錄到服務器中即可以可視化圖表的形式查看主機上所有容器的運行狀態。
而在多主機的情況下,在所有節點上運行一個 cAdvisor 再通過各自的 UI 查看監控信息顯然不太方便,同時 cAdvisor 默認只保存 2 分鐘的監控數據。
好消息是 cAdvisor 已經內置了對 Prometheus 的支持。訪問 http://localhost:8080/metrics 即可獲取到標準的 Prometheus 監控樣本輸出:
curl -L http://34.80.39.89:20000/metrics
# HELP cadvisor_version_info A metric with a constant '1' value labeled by kernel version, OS version, docker version, cadvisor vers
ion & cadvisor revision.
# TYPE cadvisor_version_info gauge
cadvisor_version_info{cadvisorRevision="4fe450a2",cadvisorVersion="v0.36.0",dockerVersion="19.03.11",kernelVersion="3.10.0-1127.8.2.
el7.x86_64",osVersion="Alpine Linux v3.10"} 1
# HELP container_cpu_load_average_10s Value of container cpu load average over the last 10 seconds.
# TYPE container_cpu_load_average_10s gauge
container_cpu_load_average_10s{id="/",image="",name=""} 0 1594199121924
container_cpu_load_average_10s{id="/docker",image="",name=""} 0 1594199121884
container_cpu_load_average_10s{id="/docker/74fff61becfd1e5972399b522bb1502f557000b7864dd9f4e0c6c320b46167f7",image="mysql:5.7",name=
"andy-mysql-v57"} 0 1594199122691
container_cpu_load_average_10s{id="/docker/bb55ca17346a604dc5a24a6ffc7fdab2f4ed20bb1e9dd982579a6c2df9664625",image="netdata/netdata"
,name="monitor_netdata"} 0 1594199122464
container_cpu_load_average_10s{id="/docker/bd890ed4682c77244d03404fe27bf906ff36dbb924fbb20e9e17f985823384d4",image="gcr.io/google_co
ntainers/cadvisor:v0.36.0",name="cadvisor"} 0 1594199121749
container_cpu_load_average_10s{id="/docker/c7cd27f1155dd12c6e29c42a7b552b24be1df6e0b03fabc5899f371fdf16a771",image="rabbitmq:3-manag
ement",name="daniel-rabbitmq-v3"} 0 1594199122578
container_cpu_load_average_10s{id="/system.slice",image="",name=""} 0 1594199122125
container_cpu_load_average_10s{id="/system.slice/NetworkManager-wait-online.service",image="",name=""} 0 1594199076780