Help us understand the problem. What is going on with this article?

EC2からメモリ情報をCloudwatchへ送る

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

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

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

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

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away