LoginSignup
5
5

More than 5 years have passed since last update.

Docker コンテナのメトリクスを CloudWatch でモニタリングする

Last updated at Posted at 2016-01-25

概要

前回 TICK stack を構築した際に telegraf の Docker input と CloudWatch output の plugin が気になったのでセットアップしてみる。

環境

AWS にインスタンスを2台用意

  • ip-172-31-17-95 : docker, Telegraf
  • ip-172-31-17-94 : docker, Telegraf

バージョンは以下の通り

  • CentOS release 6.7 (Final)
  • Docker version 1.7.1
  • Telegraf Version v0.10.0-52-g5349a3b

各種インストール

Docker インストール

$ sudo yum -y install epel-release
$ sudo yum -y install docker-io

Telegraf インストール

2016/01/25 時点のリリース版(v0.10.0)では CloudWatch output に対応していないため、ビルドする必要がある

$ sudo yum -y install golang
$ export GOPATH=`pwd`
$ go get github.com/influxdata/telegraf
$ cd $GOPATH/src/github.com/influxdata/telegraf
$ make

前回 のインスタンスの使いまわしのため、telegraf は rpm でインストール済みなので、出来たバイナリを /usr/bin/telegraf に上書きする

version 確認

$ telegraf -version
Telegraf - Version v0.10.0-52-g5349a3b

make 時に固まる場合
CentOS 6.X の BasePepo で入る git-1.7.1 だと go get gopkg.in/**** で固まったので、git-2.7.0 にアップデートしたら直った

原因
git のバグらしい
http://oranie.hatenablog.com/entry/20141104/1415103858
https://github.com/spf13/hugo/issues/297

Telegraf セットアップ

  • AWS 側での事前準備
    • IAM Role 設定
    • Credential 取得

docker input, cloudwatch output の設定

$ sudo vi /etc/telegraf/telegraf.conf
/etc/telegraf/telegraf.conf
[agent]
  interval = "10s"
  round_interval = true
  flush_interval = "10s"
  flush_jitter = "0s"
  debug = false
  hostname = ""

[[outputs.cloudwatch]]
  region = 'ap-northeast-1'
  namespace = 'InfluxData/Telegraf'          #cloudwatch 側に表示される NameSpace

[[inputs.docker]]
  endpoint = "unix:///var/run/docker.sock"
  container_names = []

Credential を環境変数にセットする

export AWS_ACCESS_KEY_ID="AKXXXXXXXXXXXXXXXXXX"
export AWS_SECRET_ACCESS_KEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

各インスタンスで telegraf 起動

$ sudo /etc/init.d/telegraf start

Docker コンテナ起動

2台のインスタンスで適当にコンテナ起動

1台目

$ sudo docker run --name nginx-1 -d -p 8080:80 nginx
$ sudo docker run --name redis-1 -d redis

2台目

$ sudo docker run --name nginx-2 -d -p 8080:80 nginx
$ sudo docker run --name redis-2 -d redis

ClowdWatch で確認

AWSコンソールの Custom Metrics に InfluxData/Telegraf が追加される

01.png

グラフ作成

以下のタグが作成される

  • cont_id (container ID)
  • cont_image (container イメージ)
  • cont_name (container 名)

上記タグを使って、特定のコンテナグループのメトリクスをグラフ化できる

グラフを作成してダッシュボードに登録

02.png

telegraf の docker input plugin で取得できるメトリクスは以下の通り

  • mem

    • total_pgmafault
    • cache
    • mapped_file
    • total_inactive_file
    • pgpgout
    • rss
    • total_mapped_file
    • writeback
    • unevictable
    • pgpgin
    • total_unevictable
    • pgmajfault
    • total_rss
    • total_rss_huge
    • total_writeback
    • total_inactive_anon
    • rss_huge
    • hierarchical_memory_limit
    • total_pgfault
    • total_active_file
    • active_anon
    • total_active_anon
    • total_pgpgout
    • total_cache
    • inactive_anon
    • active_file
    • pgfault
    • inactive_file
    • total_pgpgin
    • max_usage
    • usage
    • failcnt
    • limit
  • cpu

    • throttling_periods
    • throttling_throttled_periods
    • throttling_throttled_time
    • usage_in_kernelmode
    • usage_in_usermode
    • usage_system
    • usage_total
  • net

    • rx_dropped
    • rx_bytes
    • rx_errors
    • tx_packets
    • tx_dropped
    • rx_packets
    • tx_errors
    • tx_bytes
  • blkio

    • io_service_bytes_recursive_async
    • io_service_bytes_recursive_read
    • io_service_bytes_recursive_sync
    • io_service_bytes_recursive_total
    • io_service_bytes_recursive_write
    • io_serviced_recursive_async
    • io_serviced_recursive_read
    • io_serviced_recursive_sync
    • io_serviced_recursive_total
    • io_serviced_recursive_write

※Docker version 1.7.1 では net のメトリクス取得不可

Docker 1.9.1 では取得できた

$ telegraf -config telegraf.conf -input-filter docker -test | grep docker_net
> docker_net,cont_id=52c817ad4cf8be1294bf1c0c089a9d2b60d5753c84359d0957047b8fd361e803,cont_image=redis,cont_name=redis-3,network=eth0 rx_bytes=648i,rx_dropped=0i,rx_errors=0i,rx_packets=8i,tx_bytes=648i,tx_dropped=0i,tx_errors=0i,tx_packets=8i 1453696361692103488
5
5
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
5
5