LoginSignup
1
0

More than 5 years have passed since last update.

サーバリソースをCloudWatchへ連携する

Posted at

collectdを使用してEC2(Linux)のサーバリソースをCloudWatchへ連携する

1.対象EC2のIAMにポリシー追加

policy.json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1495084468000",
            "Effect": "Allow",
            "Action": [
                "cloudwatch:PutMetricData"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

2.EC2上でで次のシェルを実行

collectd_setup.sh
#collectdのセットアップ準備
mkdir /etc/collectd 
yum -y install collectd 
yum -y install collectd-python
chkconfig collectd on
git clone https://github.com/awslabs/collectd-cloudwatch.git /etc/collectd/
chmod 700 /etc/collectd/src/setup.py

#collectdセットアップ実行
(echo "1"; echo "1"; echo "1"; echo "1"; echo "1"; echo "1"; echo "1"; echo "2"; echo "1"; echo "3"; cat) | /etc/collectd/src/setup.py

#連携するリソースを記述
cat << 'EOW' >/opt/collectd-plugins/cloudwatch/config/whitelist.conf
df-root-percent_bytes-used
cpu--percent-active
memory--percent-used
EOW

3.確認方法

1.AWSコンソールのCloudWatch>メトリクスを開く
2.名前空間>collectdへ移動
3.EC2のinstance-idで検索
メトリクスが作成されているので、CloudWatchで監視(ERRORが出たらメール通知など)などができます。

参考

https://qiita.com/wadatin/items/7236aafe5a3f553d86ff
collectdを使わないでメトリクスを作成する方法→https://gist.github.com/inokappa/2a220eb50793094e1c0a

1
0
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
1
0