12
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

EC2のメモリ使用量とdisk使用量をcollectdでサクッとCloudWatchに登録

Last updated at Posted at 2016-10-27

CloudWatchの標準メトリックではメモリ使用量とdisk使用量が取れないので
これまでは
公式のCloudWatchMonitoringScripts をcronでcloudwatchにputしていく必要があった
あとperlのモジュールが色々必要
(古いせいなのか最新のamazonlinuxでは色々足りなかった)

めんどくさいので何か新しいやり方ないかなと思っていたところ
公式でcollectdの記事が!

しかしamazonlinuxのリポジトリにから引っ張ってこれるcollectdはまだ5.4.1
5.5以降でないとdfが取れないらしい
新しい collectd の CloudWatch プラグイン

なのでcollectdの公式から最新を引っ張ってこよう

collectdのインストール

$ wget https://storage.googleapis.com/collectd-tarballs/collectd-5.6.1.tar.bz2   or  collectd-5.5.2.tar.bz2
$ tar xvf collectd-5.6.1.tar.bz2
$ cd collectd-5.6.1
$ ./configure
$ make

エラーが発生

Can't locate ExtUtils/MakeMaker.pm in @INC

perlモジュールのインストール

$ sudo yum install perl-ExtUtils-MakeMaker
$ make clean
$ ./configure
$ make && make install

CloudWatch-Pluginのインストール

$ git clone https://github.com/awslabs/collectd-cloudwatch.git
$ collectd-cloudwatch
$ ./src/setup.py
Installing dependencies ... OK
Installing python dependencies ... OK
Downloading plugin ... OK
Extracting plugin ... OK
Moving to collectd plugins directory ... OK
Copying CloudWatch plugin include file ... OK

Choose AWS region for published metrics:
  1. Automatic [ap-northeast-1]
  2. Custom
Enter choice [1]: 1

Choose hostname for published metrics:
  1. EC2 instance id [インスタンスID]
  2. Custom
Enter choice [1]: 1

Choose authentication method:
  1. IAM Role [ロール名]
  2. IAM User
Enter choice [1]: 1

Choose how to install CloudWatch plugin in collectd:
  1. Do not modify existing collectd configuration
  2. Add plugin to the existing configuration
  3. Use CloudWatch recommended configuration (4 metrics)
Enter choice [3]: 3
Plugin configuration written successfully.
Creating backup of the original configuration ... OK
Replacing collectd configuration ... OK
Replacing whitelist configuration ... OK
Stopping collectd process ... NOT OK
Starting collectd process ... OK

/opt/collectd-plugins/cloudwatch/config/whitelist.conf
には既に以下のメトリクスが入っているのでcloudwatchでしばらく待つと使えるようになる

df-root-percent_bytes-used
memory--percent-used
swap--percent-used
cpu--percent-active

後はcollectdをdaemon登録して完了

autoscaleやAMIコピーだとインスタンスIDが違うため動かないかもしれないので
再度pluginのセットアップをするとよい

12
14
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
12
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?