株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

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

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

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

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

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)