LoginSignup
13
23

More than 5 years have passed since last update.

【Docker】cAdvisorによるDockerコンテナの監視について

Last updated at Posted at 2016-12-18

cAdvisorとは?

Googleが作成しているDockerコンテナのモニタリングツールです。

Kubernetesに組み込まれていたり、Dockerコンテナのモニタリングツールとして一般化しつつあるようなので、cAdvisorについて調査しなにが嬉しいのかについて整理してみました。

cAdvisorの動かし方

cAdvisor自体もコンテナになっているため、docker runで起動することができます。

sudo 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=cadvisor \
  google/cadvisor:latest

cAdvisor 自体も Docker で起動して、同ホスト上に起動している Docker コンテナの リソースをモニタリングしてくれます。

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.

githubにあるように、cAdvisorはホスト単位で起動中のコンテナのメトリクス情報を収集&集計しAPIとして提供してくれます。
DockerRemoteAPIを使ってごりごりと加工すれば同じようなことができるかもしれませんが、cAdvisorがそのあたりを担ってくれてるので大分楽なのではないでしょうか。

また、cAdvisorではメモリ上にデフォルトで直近60秒分の情報を保持しているので、提供しているAPIでは60秒分のメトリクス情報をとることができます。

実際にメトリクス情報を取りたい場合は、http://<ip>:<port>/api/v2.0/statsを叩くとホスト上で動いている起動中の全コンテナの60秒分のデータをとることができます。また、http://<ip>:<port>/api/v2.0/stats/<container_id>?type=dockerという形でコンテナIDを指定することで各コンテナ毎のメトリクスを返してくれるようです。

GUIを提供してくれる

cAdvisorでは以下のようなGUIも提供してくれており、

  • CPU
  • Memory
  • Network
  • FileSystem

の情報をグラフを見ることができます。

スクリーンショット 2016-12-18 17.32.25.png

簡単に起動できる

cAdvisorはコンテナで動かすことができるため、使いたい時にコンテナを起動してサクッと使うことができます。
とりあえずコンテナのメトリクスが見たい時に余計な手間がいらず楽なのではないでしょうか。

おわり

cAdvisorはメモリ上にしかメトリクス情報を持たないので実際にcAdvisorでメトリクス監視をするためには、InfluxDBにデータを投げGrafanaで可視化するといったことが必要になります。
cAdvisorのコンテナ起動時のオプションで楽にInfluxDBとの連携できるようなっているようなので今度やってみようと思います。

参考

https://jedipunkz.github.io/blog/2015/09/12/cadvisor-influxdb-grafana-docker/
http://developer.hatenastaff.com/entry/monitoring-kubernetes
https://www.infoq.com/jp/news/2016/01/dockercon-docker-monitoring
http://blog.couchbase.com/2016/april/monitoring-docker-containers-docker-stats-cadvisor-universal-control-plane
https://www.youtube.com/watch?v=sxE1vDtkYps
https://www.youtube.com/watch?v=8RY33I_KKy4
https://www.youtube.com/watch?v=dqvaibpwAWk
https://www.youtube.com/watch?v=f3URWWSyl1U

13
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
23