0
0

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からメモリ情報をCloudwatchへ送る

Posted at

メモリ情報はデフォルトの監視メトリクスにない

なんでー
自分でセットしてあげる必要があります。

以下ポリシーを持つユーザーを作成

CloudwatchとEC2へのFullAccessが付いていればいいけれど、EC2インスタンス内のフラットファイルに書き込むのでなるべく絞ったほうが良いと思う

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "cloudwatch:PutMetricData",
                "ec2:DescribeTags",
                "cloudwatch:GetMetricStatistics",
                "cloudwatch:ListMetrics"
            ],
            "Resource": "*"
        }
    ]
}

image.png

ツールのインストール

sudo yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA.x86_64
curl https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip -O
unzip CloudWatchMonitoringScripts-1.2.2.zip
cd aws-scripts-mon/
cp -p awscreds.template awscreds.conf

上記ポリシーを持っているユーザーのアクセスキーを設定

awscreds.conf
AWSAccessKeyId=xxxxxxxxxxxxxxxxxxxxx
AWSSecretKey=xxxxxxxxxxxxxxxxxxxxx

送信テスト(実際にはデータは送られない)

echo $?0ならOK

./mon-put-instance-data.pl --mem-util --swap-util --disk-space-util --disk-path=/ --verify

cronに仕込む

crontab -eで編集

*/5 * * * * ~/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-space-util --disk-path=/ --from-cron

実行確認

tail -f /var/log/cron | grep mon-put-instance-data.pl

動作確認

Linuxシステム項目が、Cloudwatch上の監視メトリクスに出現
image.png

参考

https://qiita.com/zaburo/items/98388ef35aa2e7a477e0
https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/mon-scripts.html

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?